This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Map text file to a 2 dimensional array.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Fire me boy! Cool, soothing, shameless self promotion:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!