facebook

Read From File?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #226383 Reply

    wk3000sg
    Member

    I have a problem here…How to read from .txt files using eclipse??

    #226389 Reply

    Riyad Kalla
    Member

    Do you want to open the .txt file to edit it or are you asking how to read a .txt file in Java?

    #226395 Reply

    wk3000sg
    Member

    i am suppose to get the value in the .txt and display it.
    I tink we can use FileReader right?
    But eclipse have many folders, where can i place the .txt file?
    The constructor of FileReader can only read the file if its in the same directory with the java file.

    #226397 Reply

    Riyad Kalla
    Member

    1) http://www.google.com/search?hl=en&q=Reading+files+in+Java&btnG=Google+Search

    I tink we can use FileReader right?

    Yes

    But eclipse have many folders, where can i place the .txt file?

    Wherever you want, just make sure your absolute or relative path to the file is correct. Don’t worry about “Eclipse” your file will run the same and require the same code even if you use TextPad and run it from the command line. The only different is the “Working directory”, this is the directory that your app starts up in, it will think of this directory as it’s Root.

    You can find out what directory your application is running from by using the following code:

    
    System.out.println(new File(".").getAbsolutePath());
    

    That will print out the current directory. Then from there you can establish what path you need to use for your file.

    #226434 Reply

    wk3000sg
    Member

    thx for the help.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Read From File?

You must be logged in to post in the forum log in