Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default Help with reading file into array

    I am trying to read a file into separate arrays, the program works, but when I try to print the individual arrays it returns something like this: [I@b749757, which is wrong. Each array has 125 integers in it. Any ideas on how to get it to print the correct contents of the arrays?


    for (int x = 1; x <= FILESIZE; x++){
    String temp = reader.readLine();
    if (x > 0 && x <= (FILESIZE/8))
    array1[x] = reader.read();
    if (x > FILESIZE/8 && x <= 2*(FILESIZE/8))
    array2[x-125] = Integer.parseInt(temp);
    if (x > 2*FILESIZE/8 && x <= 3*(FILESIZE/8))
    array3[x-250] = Integer.parseInt(temp);
    if (x > 3*FILESIZE/8 && x <= 4*(FILESIZE/8))
    array4[x-375] = Integer.parseInt(temp);
    if (x > 4*FILESIZE/8 && x <= 5*(FILESIZE/8))
    array5[x-500] = Integer.parseInt(temp);
    if (x > 5*FILESIZE/8 && x <= 6*(FILESIZE/8))
    array6[x-625] = Integer.parseInt(temp);
    if (x > 6*FILESIZE/8 && x <= 7*(FILESIZE/8))
    array7[x-750] = Integer.parseInt(temp);
    if (x > 7*FILESIZE/8 && x <= 8*(FILESIZE/8))
    array8[x-875] = Integer.parseInt(temp);
    }// for

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

    Default

    Your output is correct as it's the toString() result returned by array objects. If you want to print the array contents, you'll have to either iterate through the array with a for loop printing each item within the loop, or else you could call the Arrays utility class's toString method. For instance if your array was named myArray, then ...

    Java Code:
    System.out.println(java.util.Arrays.toString(myArray));

  3. #3
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Reading csv file into 2D array - HELP!!!
    By mikeg in forum New To Java
    Replies: 17
    Last Post: 04-12-2011, 09:36 AM
  2. Reading from a text file into an array
    By xyknight in forum New To Java
    Replies: 16
    Last Post: 04-11-2011, 12:10 AM
  3. Help with reading from file into an array
    By Trad in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 01:16 PM
  4. Reading a txt file and then storing it in a 2d array
    By blkshp1990 in forum New To Java
    Replies: 2
    Last Post: 11-05-2009, 01:31 AM
  5. Reading input file into an array
    By littlefire in forum New To Java
    Replies: 6
    Last Post: 10-19-2008, 12:51 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
  •