dcsimg
how i can read from console ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sebastian_Stuppan
Posted On:   Monday, March 18, 2002 05:37 AM

how i can read from console ? and save in a verctor.

Re: how i can read from console ?

Posted By:   Eric_Lindauer  
Posted On:   Wednesday, March 20, 2002 07:30 AM

There are many classes in the java.io package for handling streams. You just need to read lines from System.in, as in the example below:






import java.io.*;




public class MyClass {

public static void main ( String[] args ) throws IOException {

String command = "";

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


while ( ! command.equals ( "quit" ) ) {

System.out.print ( "type something>" );

command = in.readLine ();

System.err.println ( "You typed " + command );

}


System.err.println ( "goodbye" );

}

}




Hope this helps.


-Eric
About | Sitemap | Contact