0
I am working with a small project that performs the reading of data from a spreadsheet, aiming to facilitate the capture of exceptions, I have a class called Log Generator.
This class has a Printwriter object that performs the writing of Throwable that captures and stores in a txt file, this object is instantiated when I start my view and when I close it, my intention is to know if it is possible to terminate the recording of the file and resume it again using the same object at runtime?
My intention is to provide a button that allows those who use the application to see this file, but I’m a little confused on how to do this since the file is open for recording throughout the application run.
package br.com.layoutbuilder.domain;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
public class GeradorLog {
private PrintWriter out;
public GeradorLog() {
try {
out = new PrintWriter(new FileWriter("LogAplicativo.txt", true));
} catch (IOException e) {
e.printStackTrace();
}
}
public void gravaErro(Throwable erro) {
out.print("Erro ocorrido em: ");
out.println(new Date());
out.print("Mensagem de erro: ");
out.println(erro);
out.print("Stacktrace: ");
erro.printStackTrace(out);
}
public void close() {
if (out != null) {
out.flush();
out.close();
}
}
}
Thank you for clarifying my doubt Gustavo, very grateful!
– Lucas Barbosa