我得到了這個創建日志檔案的方法:
public static void write(String path, String content) {
try {
FileWriter fw = new FileWriter(path, true);
PrintWriter buffWrite = new PrintWriter(fw);
String row = "";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = dateFormat.format(new Date(System.currentTimeMillis()));
row = "[" now "]\n" content;
buffWrite.println(row);
buffWrite.close();
} catch (IOException e) {
e.printStackTrace();
}
}
但未創建檔案,而是出現此錯誤:
java.io.FileNotFoundException: src/main/resources/templates/log/email.log (No such file or directory)
有什么辦法解決這個問題?
uj5u.com熱心網友回復:
嘗試將 email.log 直接作為專案根檔案夾的子項和 src 的對等項。
專案根目錄/src
project_root/email.log(您的檔案)
這可能是因為您的代碼使用了相對路徑,也許如果您放置整個路徑,它也可以作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/415356.html
標籤:
下一篇:lstat和ls權限輸出有些不同
