The "in" Java Stream Classic
Last Update:2017-02-28
Source: Internet
Author: User
Stream
Import java.io.*;
public class Newiodemo {public static void main (string[] args) { try { //1. Reading input by Lines: bufferedreader in = new BufferedReader ( New FileReader (Args[0]); string s, s2 = new String (); while ((s = in.readline ())!= NULL)    S2 = = s + "\ n"; in.close (); //1b. Reading Standard Input: bufferedreader stdin = new BufferedReader ( new InputStreamReader (system.in)); system.out.print ("Enter a Line:"); system.out.println (Stdin.readline ()); //2. Input from Memory stringreader in2 = new StringReader (s2); int c; while ((c = in2.read ())!=-1) system.out.print ((char) c); //3. Formatted MEMOry input try { datainputstream in3 = New DataInputStream ( //oops:must use deprecated class: New StringBufferInputStream (S2)); while (True) System.out.print ((char) in3.readbyte ());  } catch (Eofexception e) { system.out.println ("End of Stream"); } //4. Line Numbering & file Output try { linenumberreader Li = new LineNumberReader ( new StringReader (s2 ); bufferedreader in4 = new BufferedReader (LI); printwriter out1 = new PrintWriter ( new BufferedWriter ( new FileWriter ("Iodemo.out")); while ((s = in4.readline ())!= null) out1.println ( "line" + li.getlinenumber () + s); out1.close ();  &NBSP} catch (Eofexception e) { system.out.println ("End of Stream"); } //5. Storing & recovering data try { dataoutputstream Out2 = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ("Data.txt")); out2.writedouble (3.14159); out2.writebytes ("That is PI"); out2.close (); &Nbsp; datainputstream in5 = new DataInputStream ( new Bufferedinputstream ( new FileInputStream (" Data.txt ")); bufferedreader in5br = new BufferedReader ( new inputstreamreader (in5)); //must use DataInputStream for DATA:     SYSTEM.OUT.PRINTLN ( In5.readdouble ()) //Can now use the "proper" readLine (): system.out.println (In5br.readline ());  } catch (Eofexception e) { system.out.println ("End of Stream"); } //6. Reading and writing random access //files are the same as before. //(not repeated here)    &NBSP} catch (FileNotFoundException e) { system.out.println ( "File not Found: + args[1]);  } catch (IOException e) { system.out.println ("IO Exception"); } }}///:~