How do I read input character-by-character in Java?

Posted by Jergason on Stack Overflow See other posts from Stack Overflow or by Jergason
Published on 2009-05-01T15:22:17Z Indexed on 2010/05/10 18:34 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I am used to the c-style getchar(), but it seems like there is nothing comparable for java. I am building a lexical analyzer, and I need to read in the input character by character.

I know I can use the scanner to scan in a token or line and parse through the token char-by-char, but that seems unwieldy for strings spanning multiple lines. Is there a way to just get the next character from the input buffer in Java, or should I just plug away with the Scanner class?

Edit: forgot to say where the input is coming from. The input is a file, not the keyboard.

© Stack Overflow or respective owner

Related posts about homework

Related posts about java