I have created a temp file, written to it and I want to overwrite the existing file
- Create temp file
- Fill it up
- Open old file
- Set old file to equal new one
Here is my code, but it is not working
Please let me know if you can find the issue. Thank you!
try{
//create a temporary file
File temporary=File.createTempFile("tmp", "");
BufferedWriter writer = new BufferedWriter(new FileWriter(temporary));
//Write each line to file (temporary)
for (String string : parsedArticlesToSave) {
writer.write (String.format("%s\n", string));
}
//load old file
File oldFile = new File("StringFile/ArticlesDB.txt");
//replace old file with new file
oldFile=temporary;
//release resources
writer.close();
}catch(Exception e){
e.printStackTrace();
}