populate a rectangular array from a CSV file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dilley
    New Member
    • Jun 2012
    • 4

    populate a rectangular array from a CSV file

    hllo Java Professionals!
    I need help populating an array with a CSV or tab seperated file
    I have a file called Data.txt formatted as shown below. The number of columns or rows can vary in size depending on the .txt file i tell the method to use.

    1.5 88 106 141 177
    2 157 189 251 314
    2.5 245 295 393 491
    3.25 415 498 664 830
    4 628 754 1005 1257
    5 982 1178 1571 1964
    6 1414 1696 2262 2827
    7 1924 2309 3079 3849
    8 2513 3016 4021 5027
    10 3927 4712 6283 7854
    12 5655 6786 9048 11310
    14 7697 9236 12315 15394
    16 10053 12064 16085 20106
    18 12723 15268 20358 25447
    20 15708 18850 25133 31416


    double[][] data = new Double [15] [14];
    data [0][0] = 1.5
    data [0][1] = 88
    data [1][0] = 2 and so on.

    each column represents calculated values at different line pressures. say line pressure of 50 was used for the second column and line presssure of 100 was used for the third column... i want to pass the line pressure double and the value to the method and have it search the correct line pressure column until it finds the first double larger than the value and report the value in the first column. So say I pass the double 50 and double 1000 to the method it would return 6

    Any help would be greatly appreciated
  • Dilley
    New Member
    • Jun 2012
    • 4

    #2
    Just help populating the array with the text file would be a great help!

    Comment

    • Dilley
      New Member
      • Jun 2012
      • 4

      #3
      So far this is what I have but I am getting all kinds of errors. Can anyone help me sort this out?


      Code:
       
             double[][] numbers = new double[15][14];
              
              try 
              {
                  br = new BufferedReader(new FileReader("Cylinder Pressure Chart.txt"));
                  String line = null;
      
              while ((line = br.readLine()) != null) 
              {
                  
                  for(int i=0; i<=15; i++)
                  {
                      for(int j=0; j<=14; j++)
                      {
                          numbers[i][j] = line.split("\t");
                      }
                  }

      Comment

      Working...