• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileInputStream to Array  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file that is allready formatted to initialize a 2d double array but i do not know how to initialize it while reading the file

Sample file:
{5.1,3.5,1.4,0.2,0}, {4.9,3.0,1.4,0.2,0}, {4.7,3.2,1.3,0.2,0}, {4.6,3.1,1.5,0.2,0}, {5.0,3.6,1.4,0.2,0}, {5.4,3.9,1.7,0.4,0}, {4.6,3.4,1.4,0.3,0}, {5.0,3.4,1.5,0.2,0}, {4.4,2.9,1.4,0.2,0}, {4.9,3.1,1.5,0.1,0},
{5.4,3.7,1.5,0.2,0}, {4.8,3.4,1.6,0.2,0}, {4.8,3.0,1.4,0.1,0}, {4.3,3.0,1.1,0.1,0}, {5.8,4.0,1.2,0.2,0}

I understand i can copy everything in the folder and paste it in my program but im trying to learn new things.
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First we don't have 2-D arrays in Java.
We have Arrays of Arrays ( just like Arrays of any other objects ).

Do you notice a pattern in the data you have in your file?

I think you can use that pattern to build logic to place
those numbers in your aggregate type.


 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike karl wrote:I have a file that is allready formatted to initialize a 2d double array but i do not know how to initialize it while reading the file...

Well, the first thing is to understand what the file "looks like" (the way it displays (on my screen at least) is in lots of 4 sets, but that's not what you typed).

To be honest, I'd keep each set of braces on a single line and forget about the commas between them altogether - or use them to mark the end of a "row" - but there may be other rules you haven't told us about.

Also: there are several other delimiters you can use, and "{"/"}" isn't one I'd recommend for stream reading.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!