Forums Register Login

java6 console

+Pie Number of slices to send: Send
Can someone help me understand why sun might think I would want to use java.io.console.readLine instead of BufferedReader.readLine()?

When I run this program and respond with my name I get
Hello there [C@5483cd

Why is console.readLine() not returning what I typed?


Thanks,
siegfried
+Pie Number of slices to send: Send
 

Originally posted by Siegfried Heintze:
Can someone help me understand why sun might think I would want to use java.io.console.readLine instead of BufferedReader.readLine()?

When I run this program and respond with my name I get
Hello there [C@5483cd

Why is console.readLine() not returning what I typed?



I strongly advise you to read the javadocs as they will tell you all you need to know. In http://java.sun.com/javase/6/docs/api/java/io/Console.html you'll see that console.readPassword() returns a char array, not a string. Your output is the HashCode for that array. If you go through that array a char at a time, you'll see everything that was entered.

Good luck!
+Pie Number of slices to send: Send
Try something like:

(note: untested code)
[ April 17, 2007: Message edited by: pete stein ]
+Pie Number of slices to send: Send
Also, I forgot to mention that if you inspect the Javadocs for String you'll find a constructor that takes a char[] as an argument.
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1258 times.
Similar Threads
Sample on how to work with XPATH
How to detect EOF when using java.io.BufferedReader?
Wanted: Help serializing Generic Maps!
How to Serialize Maps?
How to implement and serialize nested Maps?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:56:38.