How to Read a Line of Input Using Version 1.4.2

K

kvnsmnsn

I've been working with Java version 1.5 for some time, but now I have
a new job where the Java version they use is 1.4.2, which means it
doesn't allow class <Scanner>. Does anybody out there know how to
read a line of input from the user that will work with version 1.4.2?
I'm guessing I have to use <System.in> somewhere, but I don't know
precisely how to do it. Any information would be appreciated.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
K

Kimba

Try to create a convenience method like this:

private String input(String prompt) {
//--- Write out the prompt
System.out.print(prompt);
//--- Create a Reader
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
//--- Read the user's input
try {
return br.readLine();
}
//--- We had an exception: Return NULL
catch(IOException e) {
return null;
}
}
 
K

kvnsmnsn

Try to create a convenience method like this:

private String input(String prompt) {
//--- Write out the prompt
System.out.print(prompt);
//--- Create a Reader
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
//--- Read the user's input
try {
return br.readLine();
}
//--- We had an exception: Return NULL
catch(IOException e) {
return null;
}
}


Thanks! This worked just fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top