오류 로그를 파일에 쓰는 프로그램을 만들고 있지만 파일을 저장할 때 예외가 발생하지 않습니다. 내가 뭘 잘못 했니?파일 저장시 파일을 저장하지 않습니다.
"저장"버튼의 actionListener :
public void actionPerformed(ActionEvent arg0) {
String savePath = getSavePath();
try {
saveFile(savePath);
} catch (IOException e) {
e.printStackTrace();
}
}
그리고 세 개의 파일 방법 : 귀하의 getLogFileName(...)
기능은 당신이 그것을 공급 경로에 아무것도되지
private String getSavePath() {
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(this);
return fc.getSelectedFile().getAbsolutePath();
}
private void saveFile(String path) throws IOException {
File outFile = createFile(path);
FileWriter out = null;
out = new FileWriter(outFile);
out.write("Hey");
out.close();
}
private File createFile(String path) {
String fileName = getLogFileName(path);
while (new File(fileName).exists()) {
fileCounter++;
fileName = getLogFileName(path);
}
File outFile = new File(fileName);
try {
outFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return outFile;
}
private String getLogFileName(String path) {
return "enchantcalc_err_log_" + fileCounter + ".txt";
}
일부 디버그를 만들었 으면 "클릭"액션에 도달 했습니까? – Zakaria
'ActionListener'를'add()'했습니까? – jlordo