File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes System.in.read() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "System.in.read()" Watch "System.in.read()" New topic
Author

System.in.read()

fred bates
Greenhorn

Joined: Jan 25, 2002
Posts: 1
When I use System.in.read to re trieve int values
from the keyboard I seem to be getting the ASCII
value of the integer, and can't cast it to an int.
What can I do to fix this problem?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Yes, you're getting ASCII values (or rather, ISO-8859-1 values, most likely) of the characters entered by the user. You can convert the user input into a single String by wrapping System.in in an InputStreamReader, and wrapping that in a BufferedReader (which has a readLine() method). Then you can use Integer.parseInt(String) to convert the String to an int.


"I'm not back." - Bill Harding, Twister
 
IntelliJ Java IDE
 
subject: System.in.read()
 
Threads others viewed
"java.io.IOException: The handle is invalid" in Win 2000
Trouble with system.in manipulation
math program help..
System.in.read(byte b) not working?
reading input from keys
MyEclipse, The Clear Choice