|
Nov
24
|
Often you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of different words). The Scanner classes next() method can be used for this as shown in the following example.
Scanner input = new Scanner(file);
while(input.hasNext()) {
String word = input.next();
}



September 21st, 2011 at 10:24 am
[...] and for this we can use the Scanner class to perform this task. We’ll use this great post “Using Scanner to read words from text file” as a starting [...]