how to open and retrive text file(.txt)??

Discussion in 'JSP' started by mochi2732, Jun 27, 2007.

  1. mochi2732

    mochi2732 New Member

    Joined:
    Jun 27, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello... i have a process where user want some data file(textfile.txt) from somewhere for example from D:\smart\445566.txt. After user have that file, user can choose whether he want save that file or display it as a text file. I have searched many times through web but didn't find any suitable example or solution.. :(
    So..anyone here can give me some idea or code example about this problem???
    ~i'm using JSP..
    ~i really really need help here..
    ~thanks...
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    
    File inputFile = new File("C:\\test.java"); // put your filename here
       
    BufferedReader br = new BufferedReader(new FileReader(inputFile));
       
    System.out.println(br.readLine());
    System.out.println(br.readLine());
    
    response.setContentType("application/octect-stream");
    response.setHeader("Content-Disposition","attachment; filename=" + "yourfile.txt" );
    
     
  3. mochi2732

    mochi2732 New Member

    Joined:
    Jun 27, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    pradeep...
    really thankful to your coding..
    but i have question here..
    could i used the same coding if the file is on the server?
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    On a different server you mean?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice