/ Published in: Java
URL: http://www.java.happycodings.com/Core_Java/code69.html
file.txt I drink Java I sleep Java This is test string 1 This is test string 20000
Expand |
Embed | Plain Text
import java.io.*; public class BTest { { try { while((line = reader.readLine()) != null) { oldtext += line + " "; } reader.close(); // replace a word in a file //String newtext = oldtext.replaceAll("drink", "Love"); //To replace a line in a file writer.write(newtext);writer.close(); } { ioe.printStackTrace(); } } }
You need to login to post a comment.
