Read file with StreamTokenizer
import java.io.FileReader; import java.io.Reader; import java.io.StreamTokenizer; public class StreamTokenizerExample { public static void main(String[] args) throws Exception { Reader r = new FileReader("in.txt"); StreamTokenizer st = new StreamTokenizer(r); while (st.nextToken() != StreamTokenizer.TT_EOF) { System.out.println(st.sval); } r.close(); } }