Either Overwrite or Rename file
Coding Style: NetBeans IDE 4.0 Beta2 (Java)
My goal is to edit a Text File (and I am having a real hard time).
So far the only solution I have found is to OPEN the current Text File (FileReader to Chatter.txt) and create a new Text File (FileWriter to oChatter.txt), .readline all the lines that do not need changing (Catch the ones I do and edit them) and write
each line into the new text file (as shown in the code below)
String incomming = "";
File fSourceStore = new File("Chatter.txt");
File fDestStore = new File("oChatter.txt");
FileReader frStore = new FileReader(fSourceStore);
FileWriter fwStore = new FileWriter(fDestStore);
BufferedReader brStore = new BufferedReader(frStore);
BufferedWriter bwStore = new BufferedWriter(fwStore);
boolean bSearch = true;
while (bSearch == true)
incomming = brStore.readLine();
if (incomming == null)
// End of File
bSearch = false;
else if (DETERMINE IF THIS LINE NEEDS TO BE EDITED)
// EDIT THE LINE //
// Keep information in file
Now this works good except that I can't seem to find a way (afterwards) to DELETE the old Chatter.txt and rename the new oChatter.txt -> Chatter.txt
Also, isn't there a way to OVERWRITE or MODIFY the file and not have to create/rename a TEMP file (oChatter.txt) every time I want to make a slight change to the file?
There has to be like a ReaderWriter or some .Overwrite or something?
Any kind of help would be greatly appreciated.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center