Can any one tell why there is output written to file
This code receive the file path and display its contents on jsp. but nothing is displaying. when i try to write to a file i found empty file. please let me know whats the error is :


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class DisplayLog extends HttpServlet{

private String fileOutput;
HttpSession sessionid;

public void service(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{

response.setContentType("text/html");
// PrintWriter out = response.getWriter();
sessionid=request.getSession();
FileWriter first = new FileWriter(new File("first1.txt"));

String path=request.getParameter("file");

first.write("The path:"+path);

Scanner scan = null;
StringBuffer buffer;
first.write("\nThe file output is");
first.close();
try {
//String p1= "c:/example/log1.txt";
buffer = new StringBuffer();
//scan = new Scanner(new File(p1), "UTF-8");
scan = new Scanner(new File(path));
String readdata = "";
while (scan.hasNext() && (readdata = scan.nextLine()) != null) {
buffer.append(readdata).append('\n');
}
fileOutput = buffer.toString();

first.write(fileOutput);
first.close();

request.setAttribute("filecontent", fileOutput);

} catch (Exception e) {
e.printStackTrace();
} finally {
//
RequestDispatcher rd = request.getRequestDispatcher("logcontent.jsp");
rd.forward(request, response);

if(scan != null) {
scan.close();
scan = null;
}
}
}
}