File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes cin.getline for java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cin.getline for java" Watch "cin.getline for java" New topic

cin.getline for java

Joachim Milsom

Joined: Oct 30, 2002
Posts: 3
How do I read in a string entered on the keyboard in java for a simle console program???
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Regards, Rene Larsen
Dropbox Invite
Joachim Milsom

Joined: Oct 30, 2002
Posts: 3
BufferedReader consoleIn = new BufferedReader(new InputStreamReader(;

System.out.println("Please enter a player:");
char name[] = String.parse(consoleIn.readLine());
I sort of knew it was System.In and I can work it out for an integer (int option = Integer.parseInt(consoleIn.readLine()) but not for a string. Any help would be great,
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Ahem, readLine() *is* returning a String...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
In case it's needed, a second ahem:
String myString = consoleIn.readLine() ;
In case it's not yet an oft read resource: The J2SE API Documentation
In case you hadn't read it yet: Joachim, Welcome to JavaRanch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Consider Paul's rocket mass heater.
subject: cin.getline for java
It's not a secret anymore!