lskuff
September 16th, 2004, 06:59 PM
Hi I was wondering if someone could help me with a file input question. I have some data in a file and I need to get it out in a certain format. Here is the format it is in the file:
value1: this, that, thou
special2: get, cat, meow, through
extra3: true, false
I need to get the data out so I can add the values to String variables with no spaces before or after the string so it would be the equivalent of going like:
string = "value1"
sting2 = "this"
string3 = "that"
string4 = "thou"
string5 = "special2"
string6 = "get"
etc...
Here is what I have so far:
BufferedReader in = new BufferedReader(new FileReader(fileName));
string = in.readLine();
StringTokenizer st = new StringTokenizer(string, ":" );
string1 = st.nextToken();
StringTokenizer st2 = new StringTokenizer(st.nextToken(), "," );
string2 = st2.nextToken()
string3 = st2.nextToken()
etc....
This is just a start of the code I know I need to add loops and stuff but mainly I just need some help on how to get the data out how I want it to be and how to make sure there are no spaces before or after the strings.
Thanks
value1: this, that, thou
special2: get, cat, meow, through
extra3: true, false
I need to get the data out so I can add the values to String variables with no spaces before or after the string so it would be the equivalent of going like:
string = "value1"
sting2 = "this"
string3 = "that"
string4 = "thou"
string5 = "special2"
string6 = "get"
etc...
Here is what I have so far:
BufferedReader in = new BufferedReader(new FileReader(fileName));
string = in.readLine();
StringTokenizer st = new StringTokenizer(string, ":" );
string1 = st.nextToken();
StringTokenizer st2 = new StringTokenizer(st.nextToken(), "," );
string2 = st2.nextToken()
string3 = st2.nextToken()
etc....
This is just a start of the code I know I need to add loops and stuff but mainly I just need some help on how to get the data out how I want it to be and how to make sure there are no spaces before or after the strings.
Thanks