-1
Hello!
I need to rename a file txt
, that txt
is scheme for system log. Each day has its own log.txt
. I am using the following parameters to validate the file and rename, if the file exists and if the first line of the file is the current date, if not, the file should be renamed (It was the only way I found, also accepted suggestions to do better).
Code
//connTXT.getPath() = "C:\\Users\\" + nomePc + "\\Documents\\Logs\\log.txt";
File file = new File(connTXT.getPath());
if(file.exists() && !linha.equals(dataAtual)){
//connTXT.getDiretorioPastaLog() = "C:\\Users\\" + nomePc + "\\Documents\\Logs";
// Renomear o arquivo
file.renameTo(new File(connTXT.getDiretorioPastaLog(),"Teste.txt")); // <== Dúvidas aqui
}
No visible errors, just do not rename the file.
I’ll check, although it’s been busy here these days and I haven’t touched the project again. As soon as I get this weekend I’ll share it with you. I will try the technique of creating a temporary folder or even using the folder
temp
windows. I will also debug to check if the file is open at the time of renaming. Thanks to all.– Ronison Matos