Results 1 to 4 of 4
  1. #1
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default Error reading file

    Java Code:
        FileInputStream fstream = new FileInputStream("C:/Users/Steve/Desktop/file.txt");
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
    I keep getting Error: C:\Users\Steve\Desktop\file.txt (The system cannot find the file specified)
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at matrixapplication.Matrix.getValAt(Matrix.java:36)
    at matrixapplication.Main.main(Main.java:20)
    Java Result: 1

    Im 100000x sure the file is there

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    There may be a better approach, but you could always use a filechooser.

    There is definitely a better approach but I figured Id give you a suggestion.

    Try creating a file object also.
    File (Java 2 Platform SE v1.4.2)

    You could also try
    Java Code:
    File file = new File("C:\\MyFile.txt");
    Give all those a shot and see if any of them work

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default

    On the command line cd to the Desktop directory and type "dir *.txt" (without the quotes) to see if the file is there. Remember Java is case sensitive.

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default

    ahh..found the problem. I named it file.txt, thinking the extension actually made a difference, but I guess not, so it was saving it as file.txt.txt :D

Similar Threads

  1. Reading A CSV file error.
    By jetnor in forum New To Java
    Replies: 3
    Last Post: 02-05-2011, 03:51 AM
  2. Error on reading text from a file.
    By ethann_91 in forum New To Java
    Replies: 1
    Last Post: 01-19-2010, 03:13 PM
  3. error in reading objects from file
    By sakshi in forum New To Java
    Replies: 3
    Last Post: 07-27-2009, 08:17 AM
  4. Error Message when reading an input file.
    By Deluyxe in forum New To Java
    Replies: 8
    Last Post: 04-26-2009, 04:02 PM
  5. reading from a zip file, error
    By Mr tuition in forum AWT / Swing
    Replies: 1
    Last Post: 01-16-2008, 12:39 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
  •