Results 1 to 3 of 3
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Problems with arrays

    I have to read a large text file into an array and sort each of the columns. The text file is set out so that it is in lines for each patient, and then between each piece of information about that patient, there is a certain amount of whitespace. I was thinking of using a 2D array to put it all in, but the problem is I can't work out how to split each line up so that each piece of info is in its own spot in the array.

    Basically, the text file looks like this:

    Java Code:
    1     name       15    285    806    180
    2     name2      50    850    710    107
    3     name3      13    105    185    160
    Thanks!
    Marcus:cool:

  2. #2
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    Have you written any code? In any case, you should consider using StringTokenizer for the purpose of splitting entries etc.

    Here is a good example.

    Greetings.

    Albert
    :rolleyes:

  3. #3
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    Oh, I'm definitely not expecting anyone to do any work for me. I was just totally stuck as to how to split the file, and I kind of assumed that was my starting place.

    All I've done so far is read the file in with BufferedReader:

    Java Code:
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    
    public class Sorter {
        public static void main(String[] args) {
    
            double[][]dataarray;                                                                         
    
            try {
                BufferedReader input = new BufferedReader(new FileReader("file.txt"));
    
            }
    
            catch(IOException e){
                System.out.println("Unable to read file");
            }
        }
    }
    Some of the data pieces in the text file are doubles, some are ints. However, there are a few where there's an NA for a value, which makes it a string, so I've just realised I probably won't be able to handle this in a 2D array.

    Thanks
    Marcus:cool:

Similar Threads

  1. Some problems with arrays and loops
    By BHCluster in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 01:24 PM
  2. Arrays
    By bunbun in forum New To Java
    Replies: 1
    Last Post: 04-09-2008, 03:24 AM
  3. [SOLVED] Problems with arrays
    By hayjk in forum New To Java
    Replies: 3
    Last Post: 04-07-2008, 06:52 PM
  4. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 11:08 PM
  5. arrays help
    By Warren in forum New To Java
    Replies: 6
    Last Post: 11-23-2007, 08: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
  •