Java tutorial
import java.io.FileWriter; import java.io.PrintWriter; import java.util.Calendar; public class Main { static void timeStamp(String msg, PrintWriter pw) { Calendar cal = Calendar.getInstance(); pw.printf("%s %tc\n", msg, cal); } public static void main(String args[]) throws Exception { PrintWriter pw = new PrintWriter(new FileWriter("logfile.txt", true)); timeStamp("File opened", pw); pw.close(); if (pw.checkError()) System.out.println("I/O error occurred."); } }