Results 1 to 4 of 4
Thread: [SOLVED] Help...
- 04-12-2008, 07:23 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
- 04-12-2008, 10:08 PM #2
Try this and let me know if it is what you were looking for. It will accept any filetype and will overwrite the existing file with the new one. I didnt bother testing it much, but it worked with what i had except in notepad the new lines didnt actually make a new line but it looked ok in wordpad and when used as more input.
Java Code:static void replaceWord(String filename, String oldword, String newword) { String temp=""; String line; try { FileReader input = new FileReader(filename); BufferedReader bufRead = new BufferedReader(input); while ((line=bufRead.readLine())!=null) { temp += line+"\n"; } temp=temp.replace(oldword, newword); System.out.println(temp); input.close(); bufRead = null; input = null; FileWriter fstream = new FileWriter(filename); BufferedWriter out = new BufferedWriter(fstream); out.write(temp); out.close(); } catch (Exception e) { System.out.println("error"); e.printStackTrace(); } }Last edited by Chris.Brown.SPE; 04-12-2008 at 10:11 PM.
- 04-15-2008, 08:22 PM #3
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
Thanks!!! everything worked great!!!!!
Gracias!!!
- 04-15-2008, 08:49 PM #4


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks