• Post Reply Bookmark Topic Watch Topic
  • New Topic

java6 console  RSS feed

 
Siegfried Heintze
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like:

(note: untested code)
[ April 17, 2007: Message edited by: pete stein ]
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!