Q:

how to write date and time in a txt file in java servlet?

I have written a code to find response time of user selected web sites and have taken into a txt file but file doesn't exist.And I want to write the file like
current date and time              response time(ms)
2017/06/12 03:05:02                  5423
2017/06/12 03:05:03                  5008
2017/06/12 03:05:04                  5009
2017/06/12 03:05:05                  5009

And I couldn't make this in a java class because in java class i can't call request.getparameter()
so can someone make the mistakes of my code 
my code
 package Test.Servlets;
 import Test.Object.GraphObject;
 import com.google.gson.Gson;
 import java.io.BufferedWriter;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import static java.lang.Thread.sleep;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;

 @WebServlet(name = "InitialServlet", urlPatterns = {"/InitialServlet"})
 public class InitialServlet extends HttpServlet {
        static long start = 0;
        static long finish = 0;
        static long time;
        static long[] time1=new long[6];
        private static  DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd   HH:mm:ss");
        private static  DateTimeFormatter dtf =    DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        private static  DateTimeFormatter[] dates =  new DateTimeFormatter[10];

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code.      */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet InitialServlet</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet InitialServlet at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
   // processRequest(request, response);
    HttpSession current=request.getSession();
    current.setAttribute("abc", "343");
    GraphObject graphObject=new GraphObject();
     for(int i=0;i<10;i++)
     {

            String stack_url = request.getParameter("website" );

            try {
                    URL url = new URL(stack_url);
                     HttpURLConnection httpUrlConnect = (HttpURLConnection) url.openConnection();
                    httpUrlConnect.setConnectTimeout(5000);
                    start = System.currentTimeMillis();
                    httpUrlConnect.connect();

                    if (httpUrlConnect.getResponseCode() == 200) 
                    {
                        finish = System.currentTimeMillis();
                        System.out.println(stack_url + " - " + httpUrlConnect.getResponseMessage() + " took " + (finish-start) + " Milli Seconds.");
                    }

                    if (httpUrlConnect.getResponseCode() == httpUrlConnect.HTTP_NOT_FOUND) 
                    {
                    System.out.println(stack_url + " - " + httpUrlConnect.getResponseMessage() + " - " + httpUrlConnect.HTTP_NOT_FOUND);
                    } 
                } 
                catch (Exception e) 
                {

                }

                 LocalDateTime now = LocalDateTime.now();
                 finish = System.currentTimeMillis();
                 System.out.println("Total Time for page load - "+  (finish-start)+"  at  "+dtf.format(now));
                 time1[i]=finish-start;

                 time1[i]=System.currentTimeMillis();
                 dates[i]=dtf;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
             Logger.getLogger(InitialServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
             }
            FileWriter fw = new FileWriter("time.txt");
            BufferedWriter bw = new BufferedWriter(fw);
            try {
                    for (int i = 0; i < 6; i++){

                   Integer _time = (int) (long) time1[i];
                   String content = Integer.toString(_time);

                   bw.write(content);
                   bw.newLine();
                   }

                    System.out.println("Done");

                }
              catch (IOException e) {
                    e.printStackTrace();
                }

            bw.close();
            fw.close();

    graphObject.dates=dates;
    graphObject.valueArray=time1;

    Gson gson = new Gson();
    String jsonString = gson.toJson(graphObject);

    response.setContentType("application/json");

    response.getWriter().write(jsonString);

}

@Override
public String getServletInfo() {
    return "Short description";
}
}

A:

First get time and date
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
Date date = new Date();
 System.out.println(dateFormat.format(date)); //2016/11/16 12:08:43
Than use filewriter to write into file
FileWriter fw = new FileWriter("time.txt");
fw.write(dateFormat.format(date));
fw.close();

