システムの現在の日付と時刻をログ ファイル (コンピューターの起動時にバッチ ファイルによって実行される) に追加する Java プログラムを作成しようとしています。これが私のコードです。
public class LogWriter {
public static void main(String[] args) {
/* open the write file */
FileOutputStream f=null;
PrintWriter w=null;
try {
f=new FileOutputStream("log.txt");
w=new PrintWriter(f, true);
} catch (Exception e) {
System.out.println("Can't write file");
}
/* replace this with your own username */
String user="kumar116";
w.append(user+"\t");
/* c/p http://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/ */
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
w.append(dateFormat.format(date)+'\n');
/* close the write file*/
if(w!=null) {
w.close();
}
}
}
問題は、ファイルに :) を追加していないことです。誰かがここで何が問題なのか指摘できますか?
前もって感謝します。