Pages

Your Ad Here

This Blog is not to read or go through

because, I have never been such a mess


Search the blog instead

Friday, November 23, 2007

Reading String in JAVA from command line

Reading in string input from the command line in Java


import java.io.*;

public class StringReader
{

public static void main (String[] args)
{

System.out.println("Type some text and press 'Enter.'");


String string = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);

// read in user input

try
{

string = reader.readLine();

}
catch(Exception e){}
System.out.println("You typed: " + string);

// wait for user to type 'Enter' so console window won't dissapear

System.out.println("Type 'Enter' to exit.");

try
{

string = reader.readLine();

}
catch(Exception e){e.PrintStackTrace();}

}

}



Site: http://rotterdam.ics.uci.edu/info/JavaStringReading.htm

No comments:

Your Ad Here