File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Press any key to continue...

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this has been discussed million times. I need read charcters from console not waiting for <cr>. System.in.read() waits for <cr>. I can't use java.io.Console yet since compatibility. Please remind me how to read keyboard.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may have been discussed many times, but the answer is always very simple: you can't do it. Furthermore, java.io.Console doesn't help: it only provides line-buffered-non-echoed reads for reading passwords, not any kind of general console-handling.

There's a library called "JLine" out there that might do this; I'm not sure. It uses native code, as any solution would need to.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed I was under impression that java.io.Console solves the problem. It seems time to join Java net team to add the feature in 1.7.
 
Chris Treglio
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you react to intput made before a CR by subclassing FilterInputStream (with the original System.in as the underlying stream) and using your subclass to manually flush the member "in"?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Treglio:
Could you react to intput made before a CR by subclassing FilterInputStream (with the original System.in as the underlying stream) and using your subclass to manually flush the member "in"?


No. System.in.read() won't return until Enter is pressed, no matter what.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic