Results 1 to 2 of 2
  1. #1
    venkatesh90 is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Writing to a Local File from Servlet

    Hi all,

    I have a java servlet program which just gets data from an HTML form and prints it. I am trying to write that data into a file locally in my computer.

    The following is my code to do that.

    public class XMLWriteServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {

    resp.getWriter().println("The name entered is "+ req.getParameter("Name"));

    File f=new File("D:/sample.txt");
    RandomAccessFile raf=new RandomAccessFile(f,"rw");



    NOTE: req.getParameter("Name") gets the content of the textarea named "Name".

    Now when I run the code it shows the following error

    HTTP ERROR 500

    Problem accessing /XML1. Reason:

    access denied ("" "D:\sample.txt" "read")

    I don't know what to do with it... Please help me out in that ASAP.

    Thanks in Advance.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. How do i use a web-hosted file as a regular local file?
    By OriginalUtter in forum New To Java
    Replies: 6
    Last Post: 06-14-2012, 04:16 PM
  2. Strange font problem after writing my first servlet
    By BayPhilip in forum Java Servlet
    Replies: 1
    Last Post: 03-03-2011, 11:36 PM
  3. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  4. Replies: 6
    Last Post: 06-04-2009, 11:09 PM
  5. Replies: 0
    Last Post: 08-30-2008, 11:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts