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_
Kimba - 28 Mar 2007 19:50 GMT
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;
}
}
kvnsmnsn@hotmail.com - 28 Mar 2007 20:32 GMT
> Try to create a convenience method like this:
>
[quoted text clipped - 13 lines]
> }
> }
Thanks! This worked just fine.