# fill a rectangular array from a text file of doubles

• 06-17-2012, 09:28 PM
dilley
fill a rectangular array from a text file of doubles
Hello,
I am new to java and working on a project which will calculate the Hydraulic cylinder needed to hold a specific component in place while molding. I am trying to importalues into an array so i can work with the values in my application. The values are in a text file called "Cylinder Pressure Chart.txt" and is layed out as sown below.

10.5,290,30,45
1.36,25,56,85

This file currently contains 15 rows and 16 columns but this could change over time as new cylinder files are used. the code I have so far is shown below but I cant seem to get it even close to doing what I need it to do. Please help!! The array should be filled out like this

double[][] numbers = new double[15][14];

numbers [0][0] = 10.5
numbers [0][1] = 290
numbers [0][2] = 30
numbers [1][0] = 1.36
numbers [1][1] = 25
and so on...

Code:

```         //Create Array         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");                 }             }```
• 06-17-2012, 09:33 PM
JosAH
Re: fill a rectangular array from a text file of doubles
When you split a line you get an array of Strings (worth one row in your matrix?) You still have to convert those Strings to doubles.

kind regards,

Jos
• 06-17-2012, 11:29 PM
dilley
Re: fill a rectangular array from a text file of doubles
Yes, The first line of data would be split and end up the first row of the array?Thats how I want it to happen anyway, Then read the next line and split it up into the parts for the second row and so on. I have been looking for help in other forums as well and found some examples but none seem to fit exactly what I am trying to do. Also java is very new for me..
• 06-18-2012, 10:44 AM
Ksharp
Re: fill a rectangular array from a text file of doubles
It is blaming time.

[ please no spoonfeeding - mod ]

Ksharp