Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Reading a String from the Keyboard

  Asked By: Mada    Date: Jan 22    Category: Java    Views: 926
  

I have the following code:

import java.io.*;

public class StdinS {

public static void main(String[] args) {

String toolcmd;

try{

BufferedReader stdin = new BufferedReader(new InputStreamReader
(System.in));

System.out.print("SAMSET>");

while (("exit" != stdin.readLine())) {

System.out.print("SAMSET>");

toolcmd = stdin.readLine();

if (toolcmd.equals("backup")) {

System.out.println("This command will start a backup");


} //endsif

if (toolcmd.equals("exit")) {

System.out.println("Exiting System");

System.exit(0);

} //ends if

if (toolcmd.length() < 0) {
throw new IOException();}

} //end while

} //ends try

catch (IOException e)

{System.out.println(e.getMessage());}

System.exit(0);

} //ends main
}//ends class

I want to know if my stdin.readLine() is actually read ONLY when I
hit the enter key?
If so why does it not go back to the begining of my while loop when I
explicityly issue
System.out.println("\n");
System.out.println("\r");

Bascially Im trying to right a utility (with little java knowledge)
that takes a command from the keyboard and then does something then
goes back to issuing the command prompt.
Cant quite figure out why I have to hit the enter key to go back to
the top of the loop. Thanks for your time and knowledge.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Reading a String from the Keyboard Or get search suggestion and latest updates.




Tagged: