java standard input and output

Below are standard streams available in Java.

  1. System.out is standard output
  2. System.err is standard error output
  3. System.in is standard input stream

Below is sample Program to take input from standard input, i..e keyboard

import java.io.*;
class KeyboardInput{
public static void main(String args[]) throws IOException{

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

String name=””;

//! is Logical NOT operator
while(!name.equals(“exit”)){
System.out.println(“Enter data: “);
name=br.readLine();
System.out.println(“data is: “+name);
}

br.close();
r.close();
}
}

One thought on “java standard input and output”

Leave a Reply