Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Posts
    12
    Rep Power
    0

    Default how to access a file in the present folder.

    Hi everyone...

    when I am going to use files in one of my programmes.

    I am unable to access the files.

    I am using System.getProperty("user.dir"); statement to get the present location and then using the File object to access it .

    But every time I am getting the message like there is no file .

    I am using netbeans IDE 6.9.

    Can Any body please help me .
    Anantha Nag . KUNDANALA
    ph : 9052012019 , 8143195317

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Go through the File IO API documentation.

    That should be enough to guide you how to use files.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    If you are trying to access files in the same directory, you can access it with a relative path. For example:

    Java Code:
    BufferedReader in = new BufferedReader(new FileReader(new File("dataFiles/myFile.txt")));
    String line;
    while(true){
        try{
            if((line = in.readLine()) == null){
                break;
            }
            System.out.println(line);
        }catch(Exception e){}
    }
    where datafiles is a folder inside your netbeans project and myFile.txt is a text file inside of that. You do not need the System.getProperty() call to load a local file. If the file is located elsewhere, you can type in the explicit path to the file:
    Java Code:
    ...    new File("/Applications/SomeOtherFolder/dataFiles/myFile.txt") //on *nix systems

Similar Threads

  1. preventing access/locking a folder?
    By solris in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 01:20 AM
  2. Access Linux shared folder from Windows OS
    By nitinpjairaj in forum Networking
    Replies: 3
    Last Post: 08-26-2008, 07:14 PM
  3. Reading a zip/text file present in a MAC Bundle
    By Prasannaa in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2008, 04:05 PM
  4. How to read a .EML file present on Remote Desktop?
    By anil@prokarma in forum New To Java
    Replies: 0
    Last Post: 06-12-2008, 03:05 PM
  5. how to access shared file/folder in LAN
    By ksheetiz in forum Networking
    Replies: 1
    Last Post: 05-24-2008, 05:54 AM

Posting Permissions

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