0
I’m trying to record create a log file .txt
.
I can validate if the file exists using If
, but I can’t record outside the if
where the file was created. I’m a beginner and believe that the error lies more in logic than the code itself. As the purpose is to create a log file can not lose the already recorded information, you should always add new information in the file.
String path = "C:\\Users\\Ronison Matos\\Documents\\log.txt";
File file = new File(path);
long begin = System.currentTimeMillis();
if(file.exists()){
}else{
FileWriter(file));
System.out.println("Criei novo arquivo em branco para você!");
FileWriter arq = new FileWriter(file);
}
PrintWriter gravarArq = new PrintWriter(arq); // Aqui já dá o erro de acessar no "path"
gravarArq.write("Caminho da gravação: " + path);
writer.newLine();
writer.close();
It worked Augusto for help and explanation! Thank you very much!
– Ronison Matos