Results 1 to 2 of 2
  1. #1
    Flamespewer is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default reading from a .txt

    i have a file that has two digits at top showing the size of the array then the array.

    example

    Java Code:
    04 04
    01 01 01 01
    11 11 11 11 
    04 04 04 04
    23 23 23 23
    what i want to do is read in the two numbers at top then declare a 2d array of that size and read in each number into its appropriate spot in the 2d array.

    my question is why does reading in the line show the right numbers but when i try to read in the numbers individually i always get random numbers?


    good-
    Java Code:
        FileReader aFile=new FileReader("Array.txt");
        BufferedReader fReader = new BufferedReader(aFile);
        for(int i=0;i<2;i++)
    		System.out.println(mReader.readLine());
        MapFile.close();
    bad-
    Java Code:
        FileReader aFile=new FileReader("Array.txt");
        BufferedReader fReader = new BufferedReader(aFile);
        for(int i=0;i<2;i++)
    		System.out.println(mReader.read());
        MapFile.close();

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Read the API specifications for the readLine() and read() methods to find out what they do.

Similar Threads

  1. Replies: 5
    Last Post: 08-21-2009, 11:03 AM
  2. Array not reading. Plz help
    By cmizer in forum New To Java
    Replies: 14
    Last Post: 02-12-2009, 12:02 AM
  3. Reading cookies in JSP
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:12 PM
  4. Reading a file
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 12:23 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
  •