console I/O methods in java.lang.System class

The console I/O methods in System class are

System.in.read(); read a byte
System.err.print() print a value
System.err.println(); print a value followed by a newline
System.out.print(); print a value
System.out.println(); print a value followed by a newline.
System.setIn(); redirect stdin to a file
System.setErr(); redirect stderr to a file
System.setOut(); redirect stdout to a file

Example:

System.setIn(Inputstream in)

 //read a file
 System.setIn(new FileInputStream("E:/hai.txt"));
 //read first character of a file
 char c = (char) System.in.read();
 //print the first character in a file
 System.out.println(c);

System.setOut(PrintStream out)

 //create a file
 System.setOut(new PrintStream("E:/hai123.txt"));
 //text gets generated in the file
 System.out.println("This is System class!!!");

Hope this helps you. Please subscribe and comment if you have doubts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s