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.
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();
}
}