Monday, April 4, 2011

JSP program to write current date and time to a text file

String str;
java.util.Date currentDate = new java.util.Date(); //gets the current date
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
str = sdf.format(currentDate);

String nameOfTextFile =getServletContext().getRealPath("imp.txt");
try
{
        PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
        pw.println(str);
        //clean up
        pw.close();
}
catch(IOException e)
{
        out.println(e.getMessage());
}

No comments:

Post a Comment

Thanks for visiting my Blog....Ur comments n suggestions are most valuable for me...Thanks