file reading in java

Discussion in 'Java' started by naveen, Jul 5, 2005.

  1. naveen

    naveen Guest

    hi,

    i have a problem with file reading in java...
    currently i am using the following Environment:
    WSAD 5.1.0. for Windows
    Oracle 8.1.7. 8i for Windows JDK 1.3.1.08 DB2 Client
    IBM DB2 Windows XP
    i am getting the "file not found error" in my Console
    while retiving the values from the file...

    i am calling file reading method from Servlet doPost()

    here is the code snippet i used in main:

    here is the declaration of the file:
    private String _CRIT_Maintain_FileName =
    "./WEB_INF/classes/com/d_systemes/osinet/base/Critsit_Maintenance.txt";

    in servlet doPost() i am calling the file reader
    method..
    if
    !(UserValidity.isValidUser(UserCurrent,"CRIT",_CRIT_Maintain_FileName))
    {....};

    the file reading method is:
    public static boolean isValidUser(String
    currentUser,String flag,String fileName) {


    BufferedReader in= null;
    try {
    //Make sure that the Textfile exists and has valid
    data records in a SingleLine.
    //Otherwise, exceptions will occur.
    in = new BufferedReader(new FileReader(fileName));
    String str = null;
    String validUser;
    int start;
    int end;
    while ((str = in.readLine()) != null) {
    //Using ',' as a Delimeter
    if(str.charAt(0)==',')
    start=1;
    else
    start=0;
    end=str.indexOf(",");
    while
    ((validUser=str.substring(start,end))!=null)
    {
    //Checking the cuurentUser value with the text
    file value.

    if(currentUser.equalsIgnoreCase(validUser.trim()))
    {
    return(true);
    }
    start=end+1;
    end=str.indexOf(",",end+1);
    }
    }
    in.close();
    } catch (FileNotFoundException ex) {
    ex.printStackTrace();
    }




    but at the time of file reading i am getting the file
    reading exception..can u plz tell me why i am getting
    this error?...i kept the source file and the text file
    in the current directory only..
     
    naveen, Jul 5, 2005
    #1
    1. Advertising

  2. On 5 Jul 2005 05:36:14 -0700, naveen <> wrote:

    > ere is the declaration of the file:
    > private String _CRIT_Maintain_FileName =
    > "./WEB_INF/classes/com/d_systemes/osinet/base/Critsit_Maintenance.txt";


    There is your problem - that usage depends on the "current" directory.
    In a servlet you have no control over the current directory - look at
    the ServletContext API for getRealPath() and getResourceAsStream()

    Bill
     
    William Brogden, Jul 5, 2005
    #2
    1. Advertising

  3. naveen

    shakah Guest

    naveen wrote:
    > hi,
    >
    > i have a problem with file reading in java...
    >
    > [...snipped...]
    >
    > i am getting the "file not found error" in my Console
    > while retiving the values from the file...
    >
    > [...snipped...]
    >
    > private String _CRIT_Maintain_FileName =
    > "./WEB_INF/classes/com/d_systemes/osinet/base/Critsit_Maintenance.txt";
    >
    > [...snipped...]
    >
    > but at the time of file reading i am getting the file
    > reading exception..can u plz tell me why i am getting
    > this error?...i kept the source file and the text file
    > in the current directory only..


    Maybe your path is incorrect relative to the working directory? In
    other words, does something like the following work better?
    private String _CRIT_Maintain_FileName =
    "/usr/local/tomcat/webapps/yourapp/WEB_INF/classes/com/d_systemes/osinet/base/Critsit_Maintenance.txt";

    Also, make sure the user under which your servlet engine runs has
    permission to read the file.
     
    shakah, Jul 5, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    3
    Views:
    683
    Kevin Spencer
    Nov 11, 2004
  2. Luis Esteban Valencia Muñoz
    Replies:
    3
    Views:
    1,417
    Scott Allen
    Jun 4, 2005
  3. Replies:
    0
    Views:
    790
  4. Karim Ali

    Reading a file and resuming reading.

    Karim Ali, May 25, 2007, in forum: Python
    Replies:
    2
    Views:
    377
    Hrvoje Niksic
    May 25, 2007
  5. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    803
    Alf P. Steinbach
    Jul 10, 2007
Loading...

Share This Page