Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Exclamation The System cannot find the path specified error

    Hi ,

    I was trying to read a file using java code in eclipse

    File fileName = new File("F:\\Quartz\\NewJob\\input.txt");
    if(fileName.exists())
    {
    System.out.println("file exists");
    }
    BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));

    Even though the file exists in the specified location , I am getting FileNotFoundException .. Not sure where it is going wrong. COuld someone say why this exception could be even though the file exists and having permissions

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm curious why the BufferedReader line isn't inside of the if block:

    Java Code:
          File fileName = new File("F:\\Quartz\\NewJob\\input.txt");
          if (fileName.exists()) {
             System.out.println("file exists");
             BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
          }
          // BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));

    Also, you may wish to use code tags when posting code so that it's more readable. If so, please have a look at the first link in my signature links. Luck!

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by umapathy_sekar View Post
    Hi ,

    I was trying to read a file using java code in eclipse

    File fileName = new File("F:\\Quartz\\NewJob\\input.txt");
    if(fileName.exists())
    {
    System.out.println("file exists");
    }
    BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));

    Even though the file exists in the specified location , I am getting FileNotFoundException .. Not sure where it is going wrong. COuld someone say why this exception could be even though the file exists and having permissions
    Seems nothing wrong, except the best practice that Fubarable pointed. Can you post the complete error message here to see.

  4. #4
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Question

    Are you sure, you have access to mentioned location?

    Coz, code seems ok.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. System path can't be specified?
    By Indefinite Design in forum New To Java
    Replies: 0
    Last Post: 04-11-2010, 02:50 AM
  2. find file with * on the path
    By itaipee in forum New To Java
    Replies: 7
    Last Post: 07-08-2009, 08:05 AM
  3. Cannot find class in same path.
    By ribbs2521 in forum New To Java
    Replies: 4
    Last Post: 05-07-2009, 05:25 PM
  4. How to know system folder path
    By ivvgangadhar in forum New To Java
    Replies: 6
    Last Post: 11-21-2008, 08:08 AM
  5. Replies: 5
    Last Post: 07-31-2007, 04:22 PM

Posting Permissions

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