It's not a secret anymore!*
The moose likes Jython/Python and the fly likes Help reading in data from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Help reading in data from a file" Watch "Help reading in data from a file" New topic
Author

Help reading in data from a file

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hi,

So I am reading in a configuration file for a game. It holds data about the type of symbols the game has and the possible winning combinations of symbols. I wrote this program for a simpler configuration file where all of the symbols were on two characters. So I only had to read those two characters.

Now I have a line like this:

3 Silver7 Bell Bar : 2

And I need to read each of those strings into a separate variable. I'm hoping someone has ideas for a good way to do this. Also, please note that I am not using Java for this project(I know how to do this very easily in Java), I'm hoping to get some ideas as to what processes I can use.

Thanks
Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

If you're not doing this in Java, then in what language age you doing it? It would be much easier to help you if you told us in which language you're programming...

For Java, one obvious way would be to use class java.util.Properties to load a *.properties file, which contains a key-value pair on each line (where keys and values are separated with an =).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Well the company I am working for this summer has asked me to do this project in Python. I know this isn't a python forum; I'm just trying to get some ideas for determining how many characters to read into one variable.

so if I have something like:

Silver7 Bell Bar //I could look at this line and see that Silver7 is 7 chars long, Bell is 4 chars long, and Bar is 3 chars long
//so I would know to read in 7, then 4, then 3 chars

What I currently do is:


This only works for 2 characters however, I am looking for a more flexible solution since this program will be reading in a lot of these files.


Thanks
Hunter

(Note: the reason I posted this in the Java section was because the moderators there have been very helpful with my Java issues, I was looking more for ideas than language help)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help reading in data from a file