If you have to use a Scanner (as you noted in your edit), try this:
myScanner.useDelimiter("(?<=.)");
Now myScanner should read character by character.
You might want to use a BufferedReader instead (if you can) - it has a read method that reads a single character. For instance, this will read and print the first character of your file:
BufferedReader br = new BufferedReader(new FileReader("somefile.txt"));
System.out.println((char)br.read());
br.close();
If you have to use a
Scanner
(as you noted in your edit), try this:Now
myScanner
should read character by character.You might want to use a
BufferedReader
instead (if you can) - it has aread
method that reads a single character. For instance, this will read and print the first character of your file:If you're committed to using
Scanner
then you can usenext(String pattern)
.The above returns a
String
of length 1 -- that is, you get a character, but as a string.Split the line into characters using
String.toCharArray()
.You can convert in an array of chars.