File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes input and output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "input and output" Watch "input and output" New topic

input and output

ravi rajasekhar

Joined: Dec 21, 2000
Posts: 1
Please help me in asking the user to enter text, an int, long etc. That is , how do we accept input from the user. The input can be of any data type., including objects. Is there a mechanism of cin and cout like in c++. In fact, I want to teach my students asking for input in their programs like the way C++ does. How can we do the sam in JFc and AWT? Please help me as fast as U can.
Ron Pac

Joined: Dec 26, 2000
Posts: 7
I think the weakest part of my Java programming is the I/O. In fact there are huge books about this subject which I have not been able to read up on.
I'm not sure if there is a class the is advance enough to return the correct data type (String, int, float) that is needed....
Here is how I would read in an integer:
BufferedReader in = new BufferedReader(new InputStreamReader(;
String someStr = null;
int someInt = 0;
try {
someStr = in.readLine();
someInt = Integer.parseInt(someStr, 10);
catch (IOException e) { }
I guess you'd have to do this for all data types if there are no other ways.
I agree. Here's the link:
subject: input and output
It's not a secret anymore!