1
System. In
1 public class wori // set system with inputstreamreader first. in, and then use bufferedreader. This is a common method 2 {3 Public static void main (string ARGs []) 4 {5 inputstreamreader A = new inputstreamreader (system. in); // system. in is the reference of the inputstream parent class 6 bufferedreader B = new bufferedreader (a); 7 string S = NULL; 8 Try 9 {10 while (S = B. readline ())! = NULL) // use the bufferedreader method Readline () 11 {12 if (S. equalsignorecase ("exit") // 13 {14 break; 15} 16 system. out. println (S. touppercase (); 17} 18 B. close (); // B close 19} 20 catch (ioexception e) 21 {22 E. printstacktrace (); 23} 24} 25}
2
Datainputstream, dateoutputstream, bytearrayinputstream, and bytearrayoutputstream are used to directly read and write basic data types.
Public class wori {public static void main (string ARGs []) {bytearrayoutputstream baos = new bytearrayoutputstream (); // allocate memory to a byte array, dataoutputstream dos = new dataoutputstream (baos); // try {dos. writedouble (math. random (); // bytearrayinputstream BAIS = new bytearrayinputstream (baos. tobytearray (); // tobytearray () returns a byte array as the node datainputstream Dis = new datainputstream (BAIS); system. out. println (DIS. readdouble (); // dos. close (); DIS. close ();} catch (ioexception e) {system. exit (-1 );}}}
3
Printstream
public class wori{ public static void main(String args[]) { PrintStream ps = null; try { FileOutputStream fos = new FileOutputStream("d:/1.txt"); ps = new PrintStream(fos); } catch(IOException e) { System.exit(0); } System.setOut(ps); // int i = 0; while(i < 100) { System.out.println(i); i++; } ps.close(); }}