Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-24-2009, 03:06 PM
Member
 
Join Date: Mar 2009
Posts: 14
Rep Power: 0
shiva is on a distinguished road
Default No output to file
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;
}
}
}
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in writing the output in html file aks.nitw Advanced Java 5 01-18-2010 02:33 PM
Output to a text file sfe23 New To Java 4 03-26-2009 11:44 PM
Search a word(taken from one file) in another file and give the line as the output SwapnaNaidu New To Java 7 11-19-2008 03:09 PM
Simply output the result to a text file. silvia New To Java 1 08-07-2007 06:48 AM
how to write the output of the console to a file fred New To Java 1 07-24-2007 03:02 AM


All times are GMT +2. The time now is 09:37 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org