Reputation: 8279
I am looking for easiest way to read a line in Java. Once read, I want to tokenize the line. Any suggestions?
Upvotes: 0
Views: 1747
Reputation: 597076
FileUtils.readLines(..)
from commons-io
Then use String.split(regex)
rather than a tokenizer.
Upvotes: 2
Reputation: 383746
import java.util.*;
//...
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
if (sc.hasNextInt()) {
int i = sc.nextInt();
//...
}
File
, InputStream
, and String
as source (among other things)
new Scanner(new File("input.txt"))
new Scanner("some string you want to tokenize")
sc.useDelimiter(";")
sc.next("[a-z]+")
Elsewhere on stackoverflow:
Upvotes: 6