Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a Character  RSS feed

 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, Hello, I need to make a simple 'Choice' that require a character as input. Example:


The problem here is that, if the user does not input anything & press [Enter] directly, There will still be a "System.in.read();" remaining (forcing him to press [Enter] again).. This can complicate many things..

So, I would like to know if its possible to use some sort of buffer (like 'BufferedInputStream') & to read a single character - as effectively as possible..
The only thing I know with buffer is the BufferedReader .readLine.. for reading a Line (String).
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just use BufferedReader.readLine?
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or java.util.Scanner
 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thnx.This topic may be closed.
I found that I could simply use '.read()' method with either BufferedReader or BufferedInputStream.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!