0

I'm new to programming in Java, and can't find any documentation on how to read one word at a time from a file (whitespace delimiting). My file is setup like so:

Red 255 0 0 
Green 0 255 0 
Blue 0 0 255 
Yellow 255 255 0

With any number of colors listed. I'm used to programming in C++ where you can read into a string/char/int variable and it stops every time it encounters whitespace, making it easy to assign each value to struct members in a loop. Any simple equivalent in Java? All I can seem to find is line-by-line, but not word-by-word.

Luiggi Mendoza
  • 81,685
  • 14
  • 140
  • 306
Bobazonski
  • 1,405
  • 5
  • 23
  • 39
  • Line-by-line + [`StringTokenizer`](https://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html) or [regular expressions](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html). – JimmyB Dec 03 '14 at 14:29
  • Use [`Scanner`](https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html). – Luiggi Mendoza Dec 03 '14 at 14:30
  • possible duplicate of [Read next word in java](http://stackoverflow.com/questions/4574041/read-next-word-in-java) – javaHunter Dec 03 '14 at 14:39

0 Answers0