Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using string tokenizer to separate items read in from text file

807569Sep 25 2006 — edited Sep 26 2006
I have a text file with items in this format:
blue 78
red 34
green 90

I need to read in the file and then use string tokenizer to separate the words from the numbers so i can convert the numbers to int. How would I do this? This is what I have as far as inputting the file goes:
public static void main(String[] args)throws Exception
{


FileReader fr = new FileReader("C://file.txt");
BufferedReader br = new BufferedReader(fr);
String s;
StringTokenizer st = new StringTokenizer(s);




while((s = br.readLine()) != null)
{
System.out.println(s);
}

fr.close();

any help would be greatly appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2006
Added on Sep 25 2006
14 comments
409 views