Results 1 to 3 of 3
  1. #1
    kevin8160 is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default Can't read from a text file

    Hi,

    I want to read from a text file.
    Here is my code:

    package fileRelated;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;

    public class FileImport {

    public void importFile(){
    File filInput = new File("c:\\javatest\\text.txt");
    System.out.println(filInput.exists());
    BufferedReader bfrInput = null;
    try {
    bfrInput = new BufferedReader(new FileReader(filInput));
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    }
    }

    When I run the code, the output is as follows:
    --------------------------------------------------------------------
    false
    java.io.FileNotFoundException: c:\javatest\text.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at fileRelated.FileImport.importFile(FileImport.java: 16)
    at frameGUI.FrameDisplay.main(FrameDisplay.java:35)
    ----------------------------------------------------------------------

    However, the file exists in the specified folder. I am using Vista. I gave full control permission to everyone for this file to see if it can solve the problem, but no success. Could anyone help me on this problem?

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

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Hmm try this:

    open up CMD and type this: if EXIST "c:\javatest\text.txt" (ECHO.true) else (ECHO.false)
    If you get false, then the file really does not exist. If you get true, then idk :\
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

Similar Threads

  1. A more efficient way to read from a text file
    By matzahboy in forum New To Java
    Replies: 13
    Last Post: 10-14-2009, 11:35 AM
  2. Read and edit text file
    By VinTiger in forum New To Java
    Replies: 5
    Last Post: 05-14-2009, 01:18 AM
  3. Read from a text file?
    By aaronfsimons in forum New To Java
    Replies: 3
    Last Post: 05-01-2009, 04:42 AM
  4. read from text file
    By rayda in forum New To Java
    Replies: 5
    Last Post: 04-10-2009, 03:51 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

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
  •