import java.util.*; import java.text.*; import java.io.* ; public class TextLoggerExample { public static void main(String [] args) { try{ String data = " \r\n---------------\n\r"; Date dNow = new Date( ); String str = String.format("Current Date/Time : %tc", dNow ); data += str; data+= "\r\n This content will append to the end of the file \n\r"; File file =new File("logger.txt"); //if file doesnt exists, then create it if(!file.exists()){ file.createNewFile(); } //true = append file FileWriter fileWritter = new FileWriter(file.getName(),true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); bufferWritter.write(data); bufferWritter.close(); }catch(IOException e){ e.printStackTrace(); } } }