By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,638 Members | 1,408 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,638 IT Pros & Developers. It's quick & easy.

populate a rectangular array from a CSV file

P: 4
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
Jun 16 '12 #1
Share this Question
Share on Google+
2 Replies


P: 4
Just help populating the array with the text file would be a great help!
Jun 16 '12 #2

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


Expand|Select|Wrap|Line Numbers
  1.  
  2.        double[][] numbers = new double[15][14];
  3.  
  4.         try 
  5.         {
  6.             br = new BufferedReader(new FileReader("Cylinder Pressure Chart.txt"));
  7.             String line = null;
  8.  
  9.         while ((line = br.readLine()) != null) 
  10.         {
  11.  
  12.             for(int i=0; i<=15; i++)
  13.             {
  14.                 for(int j=0; j<=14; j++)
  15.                 {
  16.                     numbers[i][j] = line.split("\t");
  17.                 }
  18.             }
  19.  
Jun 16 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.