Results 1 to 4 of 4
- 06-17-2012, 08:28 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
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...
Java 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, 08:33 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-17-2012, 10:29 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
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, 09:44 AM #4
Banned
- Join Date
- Jun 2012
- Location
- Beijing,China
- Posts
- 34
- Rep Power
- 0
Similar Threads
-
Reading a text file into an Array and spliting the content into another Array
By jtothemax in forum New To JavaReplies: 15Last Post: 05-14-2012, 12:42 PM -
Can't fill the array with the object?
By Clerek in forum New To JavaReplies: 9Last Post: 02-21-2011, 12:31 AM -
Manipulate Text Properties within Specified Rectangular Inside PDF
By sherazam in forum Java SoftwareReplies: 0Last Post: 12-30-2010, 09:12 AM -
[SOLVED] Java not fill in all info for text file
By gotenks05 in forum New To JavaReplies: 0Last Post: 05-24-2009, 05:17 PM -
Array Fill Test
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks