Results 1 to 2 of 2
  1. #1
    bikashg is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Post Reading file from a class that is called by a servlet

    Hello All,

    I have a servlet, say A. Within the servlet, I make an obejct of another class, say B(this one is just a normal java class, not a servlet). And I want to use class B to open, read a text file and send it to servlet A. The servlet A will then send it back to client.

    My question is, since B is just a normal class file and not a java servlet, can I use the FileInputStream in B to open a file? I know that getServletContext().getResourceAsStream("file.txt" ); is better for servlets but since I want to open the file from a normal java class(that is called by a servlet), I think it should be possible. However, when I try it, I get a FileNotFoundException. I am working on eclipse. Any suggestions will be highly appreciated.

    Thanks.

  2. #2
    f1gh is offline Member
    Join Date
    Nov 2010
    Posts
    46
    Rep Power
    0

    Default

    well if its filenotfoundexception than that means that file is not located where you think it is. i know in netbeans the file has to be in the netbeansprojects folder for your classes to be able to see it. Not sure about eclipse. To simply not have this deliema i include the file in the main netbeans dir, the projects dir, the project dir itself, and the directory with src files as well just to be sure ( :)).

Similar Threads

  1. JFrame Hanging When Called From Another Class
    By al_Marshy_1981 in forum AWT / Swing
    Replies: 5
    Last Post: 03-30-2010, 07:04 PM
  2. called external program does not automatically write file
    By nickvandewiele in forum New To Java
    Replies: 6
    Last Post: 02-25-2010, 02:38 PM
  3. doPost() is not called in servlet logic
    By bubulina in forum Java Servlet
    Replies: 6
    Last Post: 10-28-2009, 10:19 AM
  4. Replies: 6
    Last Post: 06-04-2009, 11:09 PM
  5. Replies: 1
    Last Post: 08-07-2007, 03:47 PM

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
  •