aspose file tools*
The moose likes I/O and Streams and the fly likes Map text file to a 2 dimensional array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Map text file to a 2 dimensional array." Watch "Map text file to a 2 dimensional array." New topic
Author

Map text file to a 2 dimensional array.

Jonathan Haybok
Greenhorn

Joined: Mar 12, 2009
Posts: 16
All I want to do is store patterns that are imported from a text file. The text file would be simple asterisks that would signify an alive cell (cell with a filled background). Spaces would be just be cells that are not alive. I'm sure many of you know about the Game of Life (I've been told it's the most programmed game), and that's what I'm doing.

I have a grid that I create with 2d arrays. I fill cells in the grid by using another 2d array that just stores true/false values. So I just need to figure out how to map an input stream of character/spaces to indexes of an array.

Can anyone help me out with this? I'm having trouble figuring out how the input stream identifies characters, and how, for example, to extract the values of an asterisk that would correspond to array[0][0]. What equates to rows/columns in text files? I apologize ahead of time for my poor description of the problem. Hopefully someone understands it.

I know I will have to modify this block of code:
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8873
    
    8

A good place to start is the IO Chapter of the Java Tutorial. It explains what functionality is available in the API. I'm sure you'll find some features that make your job fairly simple.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map text file to a 2 dimensional array.