내 프로그램이하는 일을 기록하려고합니다. 현재 PrintWriter를 사용하고 있지만 출력되는 것은 모두 빈 txt 파일입니다. 가능한 경우 누군가 제 코드를 수정하거나 제안 해주십시오.파일 java에 인쇄하지 않습니다.
public class Log {
public static void log(String string){
if(string != null) {
System.out.println("log ".concat(string));
try {
PrintWriter out=new PrintWriter(new FileWriter("log.txt"));
out.println("log ".concat(string));
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void log(String[] strings) {
if (strings == null) return;
for(String string : strings) {
if (string != null) {
System.out.println("log ".concat(string));
try {
PrintWriter out=new PrintWriter(new FileWriter("log.txt"));
out.println("log ".concat(string));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}