I have seen this question many times but I have not found a solution that works for me. I am trying to rename the file to a new file name. I am getting false every time and am not sure why like most others with the same problem.
my code is as follows:
File file = new File("filePath.log");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
for(int i = 1 ; i < 300 ; i++){
bw.write(i);
if(i % 100 == 0){
File newFile = new File("filePath2.log");
if(file.renameTo(newFile)){
System.out.println("true");
} else{
System.out.println("false");
}
file = new File("filePath.log");
bw = new BufferedWriter(new FileWriter(file));
}
}
Any help is appreciated!
EDIT:
I was able to fix the problem using Files.move method
bw.close();
String newFilePath ="C:/opt/streamserve/projroot/applications/RFC_SAP_T1/wd/rfcgateway07122014" + move + ".log";
File newFile = new File(newFilePath);
Files.move(file.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
file = new File("C:/opt/streamserve/projroot/applications/RFC_SAP_T1/wd/rfcgateway.log");
fw = new FileWriter(file);
bw = new BufferedWriter(fw);
move++;