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

process a .txt file into a rectangular array

P: 4
I am trying to open a text file which is a tab seperated file of values and read them into an array. The code I have below has all kinds of errors. Can anyone help me sort it out?

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

P: 759
Sorry for that, but...
Are you sure that you post the question on the right forum ?
Some keywords in your code seems to be from Visual Basic but the syntax run far far away. (I think that look like C syntax).

Anyway, if you wish to solve that in VB / VBA I think that the best idea is to upload your .txt file and someone from here will do the job for you: open the file, declare the variable, store the values.
Jun 18 '12 #2

Expert Mod 10K+
P: 12,366
I'm not sure how you expect us to help you when you say you get all kinds of errors and then you don't tell us what they are.

However, I can say that you have at least one algorithmic error. And that's your use of the split function. Split returns an array. And yet you're assigning it to a singular element in your array.
Jun 18 '12 #3

P: 1
I d recommend that u use Datatable instead of multidimensional array which is very primitive.
Instead the Datatable can take infinite number of columns and infinite number of rows. I can send a code snippet if u are interested.
Jun 19 '12 #4

Post your reply

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