-1

What all I want to do is extract a single character every time from a text file, no matter it is a whitespace and/or new line character, till the eof. Would using ""(empty string) as a delimiter work?

scanner.next().charAt[0]

The above code will take the first character of the string returned by

scanner.next()

and ignore the rest of the part. But I want just a single character every time from a file without ignoring any.

stillanoob
  • 1,219
  • 2
  • 16
  • 27
  • possible duplicate of [Take a char input from the Scanner](http://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner) – Nir Alfasi Jul 11 '15 at 16:50

1 Answers1

3

if you want to read a file character by character, use a Reader, not a Scanner. A Scanner is for "scanning" for specific patterns.

jtahlborn
  • 50,774
  • 5
  • 71
  • 112
  • Can you please elaborate on Reader? Suppose my file's contents are: I A.\n(new line). I want each of these characters separately as 'I' , ' '(space) , 'A' , '.' , '\n'(new line character) – stillanoob Jul 12 '15 at 12:54