Line 272//: c10:NewIODemo.java Line 272// From Thinking in Java, 2nd Edition Line 272// Available at http://www.BruceEckel.com Line 272// (c) Bruce Eckel 1999 Line 272// Copyright notice in Copyright.txt Line 272// Java 1.1 IO typical usage Line 272import java.io.*; Line 272 Line 272public class NewIODemo { Line 272 public static void main(String[] args) { Line 272 try { Line 272 // 1. Reading input by lines: Line 272 BufferedReader in = Line 272 new BufferedReader( Line 272 new FileReader(args[0])); Line 272 //BufferedReader -> FileReader -> "filename" Line 272 Line 272 String s, s2 = new String(); Line 272 while((s = in.readLine())!= null) Line 272 s2 += s + "\n"; Line 272 in.close(); Line 272 Line 272 // 1b. Reading standard input: Line 272 BufferedReader stdin = Line 272 new BufferedReader( Line 272 new InputStreamReader(System.in)); Line 272 //BufferedReader -> InputStreamReader -> "Standar Input" Line 272 Line 272 System.out.print("Enter a line:"); Line 272 System.out.println(stdin.readLine()); Line 272 Line 272 // 2. Input from memory Line 272 StringReader in2 = new StringReader(s2); Line 272 int c; Line 272 while((c = in2.read()) != -1) Line 272 System.out.print((char)c); Line 272 Line 272 // 3. Formatted memory input Line 272 try { Line 272 DataInputStream in3 = Line 272 new DataInputStream( Line 272 // Oops: must use deprecated class: Line 272 new StringBufferInputStream(s2)); Line 272 //DataInputStream -> StringBufferInputStream -> "string" Line 272 Line 272 while(true) Line 272 System.out.print((char)in3.readByte()); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 // 4. Line numbering & file output Line 272 try { Line 272 LineNumberReader li = Line 272 new LineNumberReader( Line 272 new StringReader(s2)); Line 272 BufferedReader in4 = Line 272 new BufferedReader(li); Line 272 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 272 // / / Line 272 // in4 li Line 272 Line 272 PrintWriter out1 = Line 272 new PrintWriter( Line 272 new BufferedWriter( Line 272 new FileWriter("IODemo.out"))); Line 272 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 272 Line 272 while((s = in4.readLine()) != null ) Line 272 out1.println("Line " + li.getLineNumber() + s); Line 272 out1.close(); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 // 5. Storing & recovering data Line 272 try { Line 272 DataOutputStream out2 = Line 272 new DataOutputStream( Line 272 new BufferedOutputStream( Line 272 new FileOutputStream("Data.txt"))); Line 272// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 272 Line 272 out2.writeDouble(3.14159); Line 272 out2.writeBytes("That was pi"); Line 272 out2.close(); Line 272 DataInputStream in5 = Line 272 new DataInputStream( Line 272 new BufferedInputStream( Line 272 new FileInputStream("Data.txt"))); Line 272 Line 272// in5br in5 Line 272// \ \ Line 272//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 272 Line 272 BufferedReader in5br = Line 272 new BufferedReader( Line 272 new InputStreamReader(in5)); Line 272 Line 272 // Must use DataInputStream for data: Line 272 System.out.println(in5.readDouble()); Line 272 // Can now use the "proper" readLine(): Line 272 System.out.println(in5br.readLine()); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 } catch(FileNotFoundException e) { Line 272 System.out.println( Line 272 "File Not Found:" + args[1]); Line 272 } catch(IOException e) { Line 272 System.out.println("IO Exception"); Line 272 } Line 272 } Line 272} Line 272//: c10:NewIODemo.java Line 272// From Thinking in Java, 2nd Edition Line 272// Available at http://www.BruceEckel.com Line 272// (c) Bruce Eckel 1999 Line 272// Copyright notice in Copyright.txt Line 272// Java 1.1 IO typical usage Line 272import java.io.*; Line 272 Line 272public class NewIODemo { Line 272 public static void main(String[] args) { Line 272 try { Line 272 // 1. Reading input by lines: Line 272 BufferedReader in = Line 272 new BufferedReader( Line 272 new FileReader(args[0])); Line 272 //BufferedReader -> FileReader -> "filename" Line 272 Line 272 String s, s2 = new String(); Line 272 while((s = in.readLine())!= null) Line 272 s2 += s + "\n"; Line 272 in.close(); Line 272 Line 272 // 1b. Reading standard input: Line 272 BufferedReader stdin = Line 272 new BufferedReader( Line 272 new InputStreamReader(System.in)); Line 272 //BufferedReader -> InputStreamReader -> "Standar Input" Line 272 Line 272 System.out.print("Enter a line:"); Line 272 System.out.println(stdin.readLine()); Line 272 Line 272 // 2. Input from memory Line 272 StringReader in2 = new StringReader(s2); Line 272 int c; Line 272 while((c = in2.read()) != -1) Line 272 System.out.print((char)c); Line 272 Line 272 // 3. Formatted memory input Line 272 try { Line 272 DataInputStream in3 = Line 272 new DataInputStream( Line 272 // Oops: must use deprecated class: Line 272 new StringBufferInputStream(s2)); Line 272 //DataInputStream -> StringBufferInputStream -> "string" Line 272 Line 272 while(true) Line 272 System.out.print((char)in3.readByte()); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 // 4. Line numbering & file output Line 272 try { Line 272 LineNumberReader li = Line 272 new LineNumberReader( Line 272 new StringReader(s2)); Line 272 BufferedReader in4 = Line 272 new BufferedReader(li); Line 272 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 272 // / / Line 272 // in4 li Line 272 Line 272 PrintWriter out1 = Line 272 new PrintWriter( Line 272 new BufferedWriter( Line 272 new FileWriter("IODemo.out"))); Line 272 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 272 Line 272 while((s = in4.readLine()) != null ) Line 272 out1.println("Line " + li.getLineNumber() + s); Line 272 out1.close(); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 // 5. Storing & recovering data Line 272 try { Line 272 DataOutputStream out2 = Line 272 new DataOutputStream( Line 272 new BufferedOutputStream( Line 272 new FileOutputStream("Data.txt"))); Line 272// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 272 Line 272 out2.writeDouble(3.14159); Line 272 out2.writeBytes("That was pi"); Line 272 out2.close(); Line 272 DataInputStream in5 = Line 272 new DataInputStream( Line 272 new BufferedInputStream( Line 272 new FileInputStream("Data.txt"))); Line 272 Line 272// in5br in5 Line 272// \ \ Line 272//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 272 Line 272 BufferedReader in5br = Line 272 new BufferedReader( Line 272 new InputStreamReader(in5)); Line 272 Line 272 // Must use DataInputStream for data: Line 272 System.out.println(in5.readDouble()); Line 272 // Can now use the "proper" readLine(): Line 272 System.out.println(in5br.readLine()); Line 272 } catch(EOFException e) { Line 272 System.out.println("End of stream"); Line 272 } Line 272 Line 272 } catch(FileNotFoundException e) { Line 272 System.out.println( Line 272 "File Not Found:" + args[1]); Line 272 } catch(IOException e) { Line 272 System.out.println("IO Exception"); Line 272 } Line 272 } Line 272} Line 272//: c10:NewIODemo.java Line 272// From Thinking in Java, 2nd Edition Line 272// Available at http://www.BruceEckel.com Line 272// (c) Bruce Eckel 1999 Line 272// Copyright notice in Copyright.txt Line 272// Java 1.1 IO typical usage Line 272import java.io.*; Line 272 Line 272public class NewIODemo { Line 272 public static void main(String[] args) { Line 272 try { Line 272 // 1. Reading input by lines: Line 272 BufferedReader in = Line 272 new BufferedReader( Line 272 new FileReader(args[0])); Line 272 //BufferedReader -> FileReader -> "filename" Line 272 Line 272 String s, s2 = new String(); Line 272 while((s = in.readLine())!= null) Line 272 s2 += s + "\n"; Line 272 in.close(); Line 272 Line 272 // 1b. Reading standard input: Line 272 BufferedReader stdin = Line 272 new BufferedReader( Line 272 new InputStreamReader(System.in)); Line 272 //BufferedReader -> InputStreamReader -> "Standar Input" Line 272 Line 272 System.out.print("Enter a line:"); Line 272 System.out.println(stdin.readLine()); Line 272 Line 272 // 2. Input from memory Line 272 StringReader in2 = new StringReader(s2); Line 272 int c; Line 272 while((c = in2.read()) != -1) Line 272 System.out.print((char)c); Line 272 Line 272 // 3. Formatted memory input Line 272 try { Line 272 DataInputStream in3 = Line 272 new DataInputStream( Line 272 // Oops: must use deprecated class: Line 542 new StringBufferInputStream(s2)); Line 542 //DataInputStream -> StringBufferInputStream -> "string" Line 542 Line 542 while(true) Line 542 System.out.print((char)in3.readByte()); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 4. Line numbering & file output Line 542 try { Line 542 LineNumberReader li = Line 542 new LineNumberReader( Line 542 new StringReader(s2)); Line 542 BufferedReader in4 = Line 542 new BufferedReader(li); Line 542 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 542 // / / Line 542 // in4 li Line 542 Line 542 PrintWriter out1 = Line 542 new PrintWriter( Line 542 new BufferedWriter( Line 542 new FileWriter("IODemo.out"))); Line 542 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 542 Line 542 while((s = in4.readLine()) != null ) Line 542 out1.println("Line " + li.getLineNumber() + s); Line 542 out1.close(); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 5. Storing & recovering data Line 542 try { Line 542 DataOutputStream out2 = Line 542 new DataOutputStream( Line 542 new BufferedOutputStream( Line 542 new FileOutputStream("Data.txt"))); Line 542// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 542 Line 542 out2.writeDouble(3.14159); Line 542 out2.writeBytes("That was pi"); Line 542 out2.close(); Line 542 DataInputStream in5 = Line 542 new DataInputStream( Line 542 new BufferedInputStream( Line 542 new FileInputStream("Data.txt"))); Line 542 Line 542// in5br in5 Line 542// \ \ Line 542//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 542 Line 542 BufferedReader in5br = Line 542 new BufferedReader( Line 542 new InputStreamReader(in5)); Line 542 Line 542 // Must use DataInputStream for data: Line 542 System.out.println(in5.readDouble()); Line 542 // Can now use the "proper" readLine(): Line 542 System.out.println(in5br.readLine()); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 } catch(FileNotFoundException e) { Line 542 System.out.println( Line 542 "File Not Found:" + args[1]); Line 542 } catch(IOException e) { Line 542 System.out.println("IO Exception"); Line 542 } Line 542 } Line 542} Line 542//: c10:NewIODemo.java Line 542// From Thinking in Java, 2nd Edition Line 542// Available at http://www.BruceEckel.com Line 542// (c) Bruce Eckel 1999 Line 542// Copyright notice in Copyright.txt Line 542// Java 1.1 IO typical usage Line 542import java.io.*; Line 542 Line 542public class NewIODemo { Line 542 public static void main(String[] args) { Line 542 try { Line 542 // 1. Reading input by lines: Line 542 BufferedReader in = Line 542 new BufferedReader( Line 542 new FileReader(args[0])); Line 542 //BufferedReader -> FileReader -> "filename" Line 542 Line 542 String s, s2 = new String(); Line 542 while((s = in.readLine())!= null) Line 542 s2 += s + "\n"; Line 542 in.close(); Line 542 Line 542 // 1b. Reading standard input: Line 542 BufferedReader stdin = Line 542 new BufferedReader( Line 542 new InputStreamReader(System.in)); Line 542 //BufferedReader -> InputStreamReader -> "Standar Input" Line 542 Line 542 System.out.print("Enter a line:"); Line 542 System.out.println(stdin.readLine()); Line 542 Line 542 // 2. Input from memory Line 542 StringReader in2 = new StringReader(s2); Line 542 int c; Line 542 while((c = in2.read()) != -1) Line 542 System.out.print((char)c); Line 542 Line 542 // 3. Formatted memory input Line 542 try { Line 542 DataInputStream in3 = Line 542 new DataInputStream( Line 542 // Oops: must use deprecated class: Line 542 new StringBufferInputStream(s2)); Line 542 //DataInputStream -> StringBufferInputStream -> "string" Line 542 Line 542 while(true) Line 542 System.out.print((char)in3.readByte()); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 4. Line numbering & file output Line 542 try { Line 542 LineNumberReader li = Line 542 new LineNumberReader( Line 542 new StringReader(s2)); Line 542 BufferedReader in4 = Line 542 new BufferedReader(li); Line 542 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 542 // / / Line 542 // in4 li Line 542 Line 542 PrintWriter out1 = Line 542 new PrintWriter( Line 542 new BufferedWriter( Line 542 new FileWriter("IODemo.out"))); Line 542 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 542 Line 542 while((s = in4.readLine()) != null ) Line 542 out1.println("Line " + li.getLineNumber() + s); Line 542 out1.close(); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 5. Storing & recovering data Line 542 try { Line 542 DataOutputStream out2 = Line 542 new DataOutputStream( Line 542 new BufferedOutputStream( Line 542 new FileOutputStream("Data.txt"))); Line 542// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 542 Line 542 out2.writeDouble(3.14159); Line 542 out2.writeBytes("That was pi"); Line 542 out2.close(); Line 542 DataInputStream in5 = Line 542 new DataInputStream( Line 542 new BufferedInputStream( Line 542 new FileInputStream("Data.txt"))); Line 542 Line 542// in5br in5 Line 542// \ \ Line 542//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 542 Line 542 BufferedReader in5br = Line 542 new BufferedReader( Line 542 new InputStreamReader(in5)); Line 542 Line 542 // Must use DataInputStream for data: Line 542 System.out.println(in5.readDouble()); Line 542 // Can now use the "proper" readLine(): Line 542 System.out.println(in5br.readLine()); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 } catch(FileNotFoundException e) { Line 542 System.out.println( Line 542 "File Not Found:" + args[1]); Line 542 } catch(IOException e) { Line 542 System.out.println("IO Exception"); Line 542 } Line 542 } Line 542} Line 542//: c10:NewIODemo.java Line 542// From Thinking in Java, 2nd Edition Line 542// Available at http://www.BruceEckel.com Line 542// (c) Bruce Eckel 1999 Line 542// Copyright notice in Copyright.txt Line 542// Java 1.1 IO typical usage Line 542import java.io.*; Line 542 Line 542public class NewIODemo { Line 542 public static void main(String[] args) { Line 542 try { Line 542 // 1. Reading input by lines: Line 542 BufferedReader in = Line 542 new BufferedReader( Line 542 new FileReader(args[0])); Line 542 //BufferedReader -> FileReader -> "filename" Line 542 Line 542 String s, s2 = new String(); Line 542 while((s = in.readLine())!= null) Line 542 s2 += s + "\n"; Line 542 in.close(); Line 542 Line 542 // 1b. Reading standard input: Line 542 BufferedReader stdin = Line 542 new BufferedReader( Line 542 new InputStreamReader(System.in)); Line 542 //BufferedReader -> InputStreamReader -> "Standar Input" Line 542 Line 542 System.out.print("Enter a line:"); Line 542 System.out.println(stdin.readLine()); Line 542 Line 542 // 2. Input from memory Line 542 StringReader in2 = new StringReader(s2); Line 542 int c; Line 542 while((c = in2.read()) != -1) Line 542 System.out.print((char)c); Line 542 Line 542 // 3. Formatted memory input Line 542 try { Line 542 DataInputStream in3 = Line 542 new DataInputStream( Line 542 // Oops: must use deprecated class: Line 542 new StringBufferInputStream(s2)); Line 542 //DataInputStream -> StringBufferInputStream -> "string" Line 542 Line 542 while(true) Line 542 System.out.print((char)in3.readByte()); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 4. Line numbering & file output Line 542 try { Line 542 LineNumberReader li = Line 542 new LineNumberReader( Line 542 new StringReader(s2)); Line 542 BufferedReader in4 = Line 542 new BufferedReader(li); Line 542 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 542 // / / Line 542 // in4 li Line 542 Line 542 PrintWriter out1 = Line 542 new PrintWriter( Line 542 new BufferedWriter( Line 542 new FileWriter("IODemo.out"))); Line 542 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 542 Line 542 while((s = in4.readLine()) != null ) Line 542 out1.println("Line " + li.getLineNumber() + s); Line 542 out1.close(); Line 542 } catch(EOFException e) { Line 542 System.out.println("End of stream"); Line 542 } Line 542 Line 542 // 5. Storing & recovering data Line 542 try { Line 542 DataOutputStream out2 = Line 542 new DataOutputStream( Line 542 new BufferedOutputStream( Line 542 new FileOutputStream("Data.txt"))); Line 542// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 813 Line 813 out2.writeDouble(3.14159); Line 813 out2.writeBytes("That was pi"); Line 813 out2.close(); Line 813 DataInputStream in5 = Line 813 new DataInputStream( Line 813 new BufferedInputStream( Line 813 new FileInputStream("Data.txt"))); Line 813 Line 813// in5br in5 Line 813// \ \ Line 813//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 813 Line 813 BufferedReader in5br = Line 813 new BufferedReader( Line 813 new InputStreamReader(in5)); Line 813 Line 813 // Must use DataInputStream for data: Line 813 System.out.println(in5.readDouble()); Line 813 // Can now use the "proper" readLine(): Line 813 System.out.println(in5br.readLine()); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 } catch(FileNotFoundException e) { Line 813 System.out.println( Line 813 "File Not Found:" + args[1]); Line 813 } catch(IOException e) { Line 813 System.out.println("IO Exception"); Line 813 } Line 813 } Line 813} Line 813//: c10:NewIODemo.java Line 813// From Thinking in Java, 2nd Edition Line 813// Available at http://www.BruceEckel.com Line 813// (c) Bruce Eckel 1999 Line 813// Copyright notice in Copyright.txt Line 813// Java 1.1 IO typical usage Line 813import java.io.*; Line 813 Line 813public class NewIODemo { Line 813 public static void main(String[] args) { Line 813 try { Line 813 // 1. Reading input by lines: Line 813 BufferedReader in = Line 813 new BufferedReader( Line 813 new FileReader(args[0])); Line 813 //BufferedReader -> FileReader -> "filename" Line 813 Line 813 String s, s2 = new String(); Line 813 while((s = in.readLine())!= null) Line 813 s2 += s + "\n"; Line 813 in.close(); Line 813 Line 813 // 1b. Reading standard input: Line 813 BufferedReader stdin = Line 813 new BufferedReader( Line 813 new InputStreamReader(System.in)); Line 813 //BufferedReader -> InputStreamReader -> "Standar Input" Line 813 Line 813 System.out.print("Enter a line:"); Line 813 System.out.println(stdin.readLine()); Line 813 Line 813 // 2. Input from memory Line 813 StringReader in2 = new StringReader(s2); Line 813 int c; Line 813 while((c = in2.read()) != -1) Line 813 System.out.print((char)c); Line 813 Line 813 // 3. Formatted memory input Line 813 try { Line 813 DataInputStream in3 = Line 813 new DataInputStream( Line 813 // Oops: must use deprecated class: Line 813 new StringBufferInputStream(s2)); Line 813 //DataInputStream -> StringBufferInputStream -> "string" Line 813 Line 813 while(true) Line 813 System.out.print((char)in3.readByte()); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 // 4. Line numbering & file output Line 813 try { Line 813 LineNumberReader li = Line 813 new LineNumberReader( Line 813 new StringReader(s2)); Line 813 BufferedReader in4 = Line 813 new BufferedReader(li); Line 813 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 813 // / / Line 813 // in4 li Line 813 Line 813 PrintWriter out1 = Line 813 new PrintWriter( Line 813 new BufferedWriter( Line 813 new FileWriter("IODemo.out"))); Line 813 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 813 Line 813 while((s = in4.readLine()) != null ) Line 813 out1.println("Line " + li.getLineNumber() + s); Line 813 out1.close(); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 // 5. Storing & recovering data Line 813 try { Line 813 DataOutputStream out2 = Line 813 new DataOutputStream( Line 813 new BufferedOutputStream( Line 813 new FileOutputStream("Data.txt"))); Line 813// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 813 Line 813 out2.writeDouble(3.14159); Line 813 out2.writeBytes("That was pi"); Line 813 out2.close(); Line 813 DataInputStream in5 = Line 813 new DataInputStream( Line 813 new BufferedInputStream( Line 813 new FileInputStream("Data.txt"))); Line 813 Line 813// in5br in5 Line 813// \ \ Line 813//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 813 Line 813 BufferedReader in5br = Line 813 new BufferedReader( Line 813 new InputStreamReader(in5)); Line 813 Line 813 // Must use DataInputStream for data: Line 813 System.out.println(in5.readDouble()); Line 813 // Can now use the "proper" readLine(): Line 813 System.out.println(in5br.readLine()); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 } catch(FileNotFoundException e) { Line 813 System.out.println( Line 813 "File Not Found:" + args[1]); Line 813 } catch(IOException e) { Line 813 System.out.println("IO Exception"); Line 813 } Line 813 } Line 813} Line 813//: c10:NewIODemo.java Line 813// From Thinking in Java, 2nd Edition Line 813// Available at http://www.BruceEckel.com Line 813// (c) Bruce Eckel 1999 Line 813// Copyright notice in Copyright.txt Line 813// Java 1.1 IO typical usage Line 813import java.io.*; Line 813 Line 813public class NewIODemo { Line 813 public static void main(String[] args) { Line 813 try { Line 813 // 1. Reading input by lines: Line 813 BufferedReader in = Line 813 new BufferedReader( Line 813 new FileReader(args[0])); Line 813 //BufferedReader -> FileReader -> "filename" Line 813 Line 813 String s, s2 = new String(); Line 813 while((s = in.readLine())!= null) Line 813 s2 += s + "\n"; Line 813 in.close(); Line 813 Line 813 // 1b. Reading standard input: Line 813 BufferedReader stdin = Line 813 new BufferedReader( Line 813 new InputStreamReader(System.in)); Line 813 //BufferedReader -> InputStreamReader -> "Standar Input" Line 813 Line 813 System.out.print("Enter a line:"); Line 813 System.out.println(stdin.readLine()); Line 813 Line 813 // 2. Input from memory Line 813 StringReader in2 = new StringReader(s2); Line 813 int c; Line 813 while((c = in2.read()) != -1) Line 813 System.out.print((char)c); Line 813 Line 813 // 3. Formatted memory input Line 813 try { Line 813 DataInputStream in3 = Line 813 new DataInputStream( Line 813 // Oops: must use deprecated class: Line 813 new StringBufferInputStream(s2)); Line 813 //DataInputStream -> StringBufferInputStream -> "string" Line 813 Line 813 while(true) Line 813 System.out.print((char)in3.readByte()); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 // 4. Line numbering & file output Line 813 try { Line 813 LineNumberReader li = Line 813 new LineNumberReader( Line 813 new StringReader(s2)); Line 813 BufferedReader in4 = Line 813 new BufferedReader(li); Line 813 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 813 // / / Line 813 // in4 li Line 813 Line 813 PrintWriter out1 = Line 813 new PrintWriter( Line 813 new BufferedWriter( Line 813 new FileWriter("IODemo.out"))); Line 813 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 813 Line 813 while((s = in4.readLine()) != null ) Line 813 out1.println("Line " + li.getLineNumber() + s); Line 813 out1.close(); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 // 5. Storing & recovering data Line 813 try { Line 813 DataOutputStream out2 = Line 813 new DataOutputStream( Line 813 new BufferedOutputStream( Line 813 new FileOutputStream("Data.txt"))); Line 813// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 813 Line 813 out2.writeDouble(3.14159); Line 813 out2.writeBytes("That was pi"); Line 813 out2.close(); Line 813 DataInputStream in5 = Line 813 new DataInputStream( Line 813 new BufferedInputStream( Line 813 new FileInputStream("Data.txt"))); Line 813 Line 813// in5br in5 Line 813// \ \ Line 813//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 813 Line 813 BufferedReader in5br = Line 813 new BufferedReader( Line 813 new InputStreamReader(in5)); Line 813 Line 813 // Must use DataInputStream for data: Line 813 System.out.println(in5.readDouble()); Line 813 // Can now use the "proper" readLine(): Line 813 System.out.println(in5br.readLine()); Line 813 } catch(EOFException e) { Line 813 System.out.println("End of stream"); Line 813 } Line 813 Line 813 } catch(FileNotFoundException e) { Line 813 System.out.println( Line 813 "File Not Found:" + args[1]); Line 813 } catch(IOException e) { Line 813 System.out.println("IO Exception"); Line 813 } Line 813 } Line 813} Line 813//: c10:NewIODemo.java Line 813// From Thinking in Java, 2nd Edition Line 813// Available at http://www.BruceEckel.com Line 813// (c) Bruce Eckel 1999 Line 813// Copyright notice in Copyright.txt Line 813// Java 1.1 IO typical usage Line 813import java.io.*; Line 813 Line 1084public class NewIODemo { Line 1084 public static void main(String[] args) { Line 1084 try { Line 1084 // 1. Reading input by lines: Line 1084 BufferedReader in = Line 1084 new BufferedReader( Line 1084 new FileReader(args[0])); Line 1084 //BufferedReader -> FileReader -> "filename" Line 1084 Line 1084 String s, s2 = new String(); Line 1084 while((s = in.readLine())!= null) Line 1084 s2 += s + "\n"; Line 1084 in.close(); Line 1084 Line 1084 // 1b. Reading standard input: Line 1084 BufferedReader stdin = Line 1084 new BufferedReader( Line 1084 new InputStreamReader(System.in)); Line 1084 //BufferedReader -> InputStreamReader -> "Standar Input" Line 1084 Line 1084 System.out.print("Enter a line:"); Line 1084 System.out.println(stdin.readLine()); Line 1084 Line 1084 // 2. Input from memory Line 1084 StringReader in2 = new StringReader(s2); Line 1084 int c; Line 1084 while((c = in2.read()) != -1) Line 1084 System.out.print((char)c); Line 1084 Line 1084 // 3. Formatted memory input Line 1084 try { Line 1084 DataInputStream in3 = Line 1084 new DataInputStream( Line 1084 // Oops: must use deprecated class: Line 1084 new StringBufferInputStream(s2)); Line 1084 //DataInputStream -> StringBufferInputStream -> "string" Line 1084 Line 1084 while(true) Line 1084 System.out.print((char)in3.readByte()); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 // 4. Line numbering & file output Line 1084 try { Line 1084 LineNumberReader li = Line 1084 new LineNumberReader( Line 1084 new StringReader(s2)); Line 1084 BufferedReader in4 = Line 1084 new BufferedReader(li); Line 1084 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 1084 // / / Line 1084 // in4 li Line 1084 Line 1084 PrintWriter out1 = Line 1084 new PrintWriter( Line 1084 new BufferedWriter( Line 1084 new FileWriter("IODemo.out"))); Line 1084 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 1084 Line 1084 while((s = in4.readLine()) != null ) Line 1084 out1.println("Line " + li.getLineNumber() + s); Line 1084 out1.close(); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 // 5. Storing & recovering data Line 1084 try { Line 1084 DataOutputStream out2 = Line 1084 new DataOutputStream( Line 1084 new BufferedOutputStream( Line 1084 new FileOutputStream("Data.txt"))); Line 1084// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 1084 Line 1084 out2.writeDouble(3.14159); Line 1084 out2.writeBytes("That was pi"); Line 1084 out2.close(); Line 1084 DataInputStream in5 = Line 1084 new DataInputStream( Line 1084 new BufferedInputStream( Line 1084 new FileInputStream("Data.txt"))); Line 1084 Line 1084// in5br in5 Line 1084// \ \ Line 1084//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 1084 Line 1084 BufferedReader in5br = Line 1084 new BufferedReader( Line 1084 new InputStreamReader(in5)); Line 1084 Line 1084 // Must use DataInputStream for data: Line 1084 System.out.println(in5.readDouble()); Line 1084 // Can now use the "proper" readLine(): Line 1084 System.out.println(in5br.readLine()); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 } catch(FileNotFoundException e) { Line 1084 System.out.println( Line 1084 "File Not Found:" + args[1]); Line 1084 } catch(IOException e) { Line 1084 System.out.println("IO Exception"); Line 1084 } Line 1084 } Line 1084} Line 1084//: c10:NewIODemo.java Line 1084// From Thinking in Java, 2nd Edition Line 1084// Available at http://www.BruceEckel.com Line 1084// (c) Bruce Eckel 1999 Line 1084// Copyright notice in Copyright.txt Line 1084// Java 1.1 IO typical usage Line 1084import java.io.*; Line 1084 Line 1084public class NewIODemo { Line 1084 public static void main(String[] args) { Line 1084 try { Line 1084 // 1. Reading input by lines: Line 1084 BufferedReader in = Line 1084 new BufferedReader( Line 1084 new FileReader(args[0])); Line 1084 //BufferedReader -> FileReader -> "filename" Line 1084 Line 1084 String s, s2 = new String(); Line 1084 while((s = in.readLine())!= null) Line 1084 s2 += s + "\n"; Line 1084 in.close(); Line 1084 Line 1084 // 1b. Reading standard input: Line 1084 BufferedReader stdin = Line 1084 new BufferedReader( Line 1084 new InputStreamReader(System.in)); Line 1084 //BufferedReader -> InputStreamReader -> "Standar Input" Line 1084 Line 1084 System.out.print("Enter a line:"); Line 1084 System.out.println(stdin.readLine()); Line 1084 Line 1084 // 2. Input from memory Line 1084 StringReader in2 = new StringReader(s2); Line 1084 int c; Line 1084 while((c = in2.read()) != -1) Line 1084 System.out.print((char)c); Line 1084 Line 1084 // 3. Formatted memory input Line 1084 try { Line 1084 DataInputStream in3 = Line 1084 new DataInputStream( Line 1084 // Oops: must use deprecated class: Line 1084 new StringBufferInputStream(s2)); Line 1084 //DataInputStream -> StringBufferInputStream -> "string" Line 1084 Line 1084 while(true) Line 1084 System.out.print((char)in3.readByte()); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 // 4. Line numbering & file output Line 1084 try { Line 1084 LineNumberReader li = Line 1084 new LineNumberReader( Line 1084 new StringReader(s2)); Line 1084 BufferedReader in4 = Line 1084 new BufferedReader(li); Line 1084 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 1084 // / / Line 1084 // in4 li Line 1084 Line 1084 PrintWriter out1 = Line 1084 new PrintWriter( Line 1084 new BufferedWriter( Line 1084 new FileWriter("IODemo.out"))); Line 1084 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 1084 Line 1084 while((s = in4.readLine()) != null ) Line 1084 out1.println("Line " + li.getLineNumber() + s); Line 1084 out1.close(); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 // 5. Storing & recovering data Line 1084 try { Line 1084 DataOutputStream out2 = Line 1084 new DataOutputStream( Line 1084 new BufferedOutputStream( Line 1084 new FileOutputStream("Data.txt"))); Line 1084// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 1084 Line 1084 out2.writeDouble(3.14159); Line 1084 out2.writeBytes("That was pi"); Line 1084 out2.close(); Line 1084 DataInputStream in5 = Line 1084 new DataInputStream( Line 1084 new BufferedInputStream( Line 1084 new FileInputStream("Data.txt"))); Line 1084 Line 1084// in5br in5 Line 1084// \ \ Line 1084//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 1084 Line 1084 BufferedReader in5br = Line 1084 new BufferedReader( Line 1084 new InputStreamReader(in5)); Line 1084 Line 1084 // Must use DataInputStream for data: Line 1084 System.out.println(in5.readDouble()); Line 1084 // Can now use the "proper" readLine(): Line 1084 System.out.println(in5br.readLine()); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1084 } Line 1084 Line 1084 } catch(FileNotFoundException e) { Line 1084 System.out.println( Line 1084 "File Not Found:" + args[1]); Line 1084 } catch(IOException e) { Line 1084 System.out.println("IO Exception"); Line 1084 } Line 1084 } Line 1084} Line 1084//: c10:NewIODemo.java Line 1084// From Thinking in Java, 2nd Edition Line 1084// Available at http://www.BruceEckel.com Line 1084// (c) Bruce Eckel 1999 Line 1084// Copyright notice in Copyright.txt Line 1084// Java 1.1 IO typical usage Line 1084import java.io.*; Line 1084 Line 1084public class NewIODemo { Line 1084 public static void main(String[] args) { Line 1084 try { Line 1084 // 1. Reading input by lines: Line 1084 BufferedReader in = Line 1084 new BufferedReader( Line 1084 new FileReader(args[0])); Line 1084 //BufferedReader -> FileReader -> "filename" Line 1084 Line 1084 String s, s2 = new String(); Line 1084 while((s = in.readLine())!= null) Line 1084 s2 += s + "\n"; Line 1084 in.close(); Line 1084 Line 1084 // 1b. Reading standard input: Line 1084 BufferedReader stdin = Line 1084 new BufferedReader( Line 1084 new InputStreamReader(System.in)); Line 1084 //BufferedReader -> InputStreamReader -> "Standar Input" Line 1084 Line 1084 System.out.print("Enter a line:"); Line 1084 System.out.println(stdin.readLine()); Line 1084 Line 1084 // 2. Input from memory Line 1084 StringReader in2 = new StringReader(s2); Line 1084 int c; Line 1084 while((c = in2.read()) != -1) Line 1084 System.out.print((char)c); Line 1084 Line 1084 // 3. Formatted memory input Line 1084 try { Line 1084 DataInputStream in3 = Line 1084 new DataInputStream( Line 1084 // Oops: must use deprecated class: Line 1084 new StringBufferInputStream(s2)); Line 1084 //DataInputStream -> StringBufferInputStream -> "string" Line 1084 Line 1084 while(true) Line 1084 System.out.print((char)in3.readByte()); Line 1084 } catch(EOFException e) { Line 1084 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 4. Line numbering & file output Line 1354 try { Line 1354 LineNumberReader li = Line 1354 new LineNumberReader( Line 1354 new StringReader(s2)); Line 1354 BufferedReader in4 = Line 1354 new BufferedReader(li); Line 1354 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 1354 // / / Line 1354 // in4 li Line 1354 Line 1354 PrintWriter out1 = Line 1354 new PrintWriter( Line 1354 new BufferedWriter( Line 1354 new FileWriter("IODemo.out"))); Line 1354 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 1354 Line 1354 while((s = in4.readLine()) != null ) Line 1354 out1.println("Line " + li.getLineNumber() + s); Line 1354 out1.close(); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 5. Storing & recovering data Line 1354 try { Line 1354 DataOutputStream out2 = Line 1354 new DataOutputStream( Line 1354 new BufferedOutputStream( Line 1354 new FileOutputStream("Data.txt"))); Line 1354// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 1354 Line 1354 out2.writeDouble(3.14159); Line 1354 out2.writeBytes("That was pi"); Line 1354 out2.close(); Line 1354 DataInputStream in5 = Line 1354 new DataInputStream( Line 1354 new BufferedInputStream( Line 1354 new FileInputStream("Data.txt"))); Line 1354 Line 1354// in5br in5 Line 1354// \ \ Line 1354//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 1354 Line 1354 BufferedReader in5br = Line 1354 new BufferedReader( Line 1354 new InputStreamReader(in5)); Line 1354 Line 1354 // Must use DataInputStream for data: Line 1354 System.out.println(in5.readDouble()); Line 1354 // Can now use the "proper" readLine(): Line 1354 System.out.println(in5br.readLine()); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 } catch(FileNotFoundException e) { Line 1354 System.out.println( Line 1354 "File Not Found:" + args[1]); Line 1354 } catch(IOException e) { Line 1354 System.out.println("IO Exception"); Line 1354 } Line 1354 } Line 1354} Line 1354//: c10:NewIODemo.java Line 1354// From Thinking in Java, 2nd Edition Line 1354// Available at http://www.BruceEckel.com Line 1354// (c) Bruce Eckel 1999 Line 1354// Copyright notice in Copyright.txt Line 1354// Java 1.1 IO typical usage Line 1354import java.io.*; Line 1354 Line 1354public class NewIODemo { Line 1354 public static void main(String[] args) { Line 1354 try { Line 1354 // 1. Reading input by lines: Line 1354 BufferedReader in = Line 1354 new BufferedReader( Line 1354 new FileReader(args[0])); Line 1354 //BufferedReader -> FileReader -> "filename" Line 1354 Line 1354 String s, s2 = new String(); Line 1354 while((s = in.readLine())!= null) Line 1354 s2 += s + "\n"; Line 1354 in.close(); Line 1354 Line 1354 // 1b. Reading standard input: Line 1354 BufferedReader stdin = Line 1354 new BufferedReader( Line 1354 new InputStreamReader(System.in)); Line 1354 //BufferedReader -> InputStreamReader -> "Standar Input" Line 1354 Line 1354 System.out.print("Enter a line:"); Line 1354 System.out.println(stdin.readLine()); Line 1354 Line 1354 // 2. Input from memory Line 1354 StringReader in2 = new StringReader(s2); Line 1354 int c; Line 1354 while((c = in2.read()) != -1) Line 1354 System.out.print((char)c); Line 1354 Line 1354 // 3. Formatted memory input Line 1354 try { Line 1354 DataInputStream in3 = Line 1354 new DataInputStream( Line 1354 // Oops: must use deprecated class: Line 1354 new StringBufferInputStream(s2)); Line 1354 //DataInputStream -> StringBufferInputStream -> "string" Line 1354 Line 1354 while(true) Line 1354 System.out.print((char)in3.readByte()); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 4. Line numbering & file output Line 1354 try { Line 1354 LineNumberReader li = Line 1354 new LineNumberReader( Line 1354 new StringReader(s2)); Line 1354 BufferedReader in4 = Line 1354 new BufferedReader(li); Line 1354 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 1354 // / / Line 1354 // in4 li Line 1354 Line 1354 PrintWriter out1 = Line 1354 new PrintWriter( Line 1354 new BufferedWriter( Line 1354 new FileWriter("IODemo.out"))); Line 1354 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 1354 Line 1354 while((s = in4.readLine()) != null ) Line 1354 out1.println("Line " + li.getLineNumber() + s); Line 1354 out1.close(); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 5. Storing & recovering data Line 1354 try { Line 1354 DataOutputStream out2 = Line 1354 new DataOutputStream( Line 1354 new BufferedOutputStream( Line 1354 new FileOutputStream("Data.txt"))); Line 1354// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 1354 Line 1354 out2.writeDouble(3.14159); Line 1354 out2.writeBytes("That was pi"); Line 1354 out2.close(); Line 1354 DataInputStream in5 = Line 1354 new DataInputStream( Line 1354 new BufferedInputStream( Line 1354 new FileInputStream("Data.txt"))); Line 1354 Line 1354// in5br in5 Line 1354// \ \ Line 1354//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 1354 Line 1354 BufferedReader in5br = Line 1354 new BufferedReader( Line 1354 new InputStreamReader(in5)); Line 1354 Line 1354 // Must use DataInputStream for data: Line 1354 System.out.println(in5.readDouble()); Line 1354 // Can now use the "proper" readLine(): Line 1354 System.out.println(in5br.readLine()); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 } catch(FileNotFoundException e) { Line 1354 System.out.println( Line 1354 "File Not Found:" + args[1]); Line 1354 } catch(IOException e) { Line 1354 System.out.println("IO Exception"); Line 1354 } Line 1354 } Line 1354} Line 1354//: c10:NewIODemo.java Line 1354// From Thinking in Java, 2nd Edition Line 1354// Available at http://www.BruceEckel.com Line 1354// (c) Bruce Eckel 1999 Line 1354// Copyright notice in Copyright.txt Line 1354// Java 1.1 IO typical usage Line 1354import java.io.*; Line 1354 Line 1354public class NewIODemo { Line 1354 public static void main(String[] args) { Line 1354 try { Line 1354 // 1. Reading input by lines: Line 1354 BufferedReader in = Line 1354 new BufferedReader( Line 1354 new FileReader(args[0])); Line 1354 //BufferedReader -> FileReader -> "filename" Line 1354 Line 1354 String s, s2 = new String(); Line 1354 while((s = in.readLine())!= null) Line 1354 s2 += s + "\n"; Line 1354 in.close(); Line 1354 Line 1354 // 1b. Reading standard input: Line 1354 BufferedReader stdin = Line 1354 new BufferedReader( Line 1354 new InputStreamReader(System.in)); Line 1354 //BufferedReader -> InputStreamReader -> "Standar Input" Line 1354 Line 1354 System.out.print("Enter a line:"); Line 1354 System.out.println(stdin.readLine()); Line 1354 Line 1354 // 2. Input from memory Line 1354 StringReader in2 = new StringReader(s2); Line 1354 int c; Line 1354 while((c = in2.read()) != -1) Line 1354 System.out.print((char)c); Line 1354 Line 1354 // 3. Formatted memory input Line 1354 try { Line 1354 DataInputStream in3 = Line 1354 new DataInputStream( Line 1354 // Oops: must use deprecated class: Line 1354 new StringBufferInputStream(s2)); Line 1354 //DataInputStream -> StringBufferInputStream -> "string" Line 1354 Line 1354 while(true) Line 1354 System.out.print((char)in3.readByte()); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 4. Line numbering & file output Line 1354 try { Line 1354 LineNumberReader li = Line 1354 new LineNumberReader( Line 1354 new StringReader(s2)); Line 1354 BufferedReader in4 = Line 1354 new BufferedReader(li); Line 1354 // BufferedReader -> LineNumberReader -> StringReader -> "string" Line 1354 // / / Line 1354 // in4 li Line 1354 Line 1354 PrintWriter out1 = Line 1354 new PrintWriter( Line 1354 new BufferedWriter( Line 1354 new FileWriter("IODemo.out"))); Line 1354 // PrintWriter -> BufferedWriter -> FilerWriter -> "Filename" Line 1354 Line 1354 while((s = in4.readLine()) != null ) Line 1354 out1.println("Line " + li.getLineNumber() + s); Line 1354 out1.close(); Line 1354 } catch(EOFException e) { Line 1354 System.out.println("End of stream"); Line 1354 } Line 1354 Line 1354 // 5. Storing & recovering data Line 1354 try { Line 1354 DataOutputStream out2 = Line 1354 new DataOutputStream( Line 1354 new BufferedOutputStream( Line 1354 new FileOutputStream("Data.txt"))); Line 1354// DataOutputStream -> BufferedOutputStream -> FileOutputStream -> "filename" Line 1354 Line 1354 out2.writeDouble(3.14159); Line 1354 out2.writeBytes("That was pi"); Line 1354 out2.close(); Line 1354 DataInputStream in5 = Line 1354 new DataInputStream( Line 1354 new BufferedInputStream( Line 1380 new FileInputStream("Data.txt"))); Line 1380 Line 1380// in5br in5 Line 1380// \ \ Line 1380//Bufferedreader -> InputStreamReader -> DataInputStream -> BufferedInputStream -> FileInputStream -> "filename" Line 1380 Line 1380 BufferedReader in5br = Line 1380 new BufferedReader( Line 1380 new InputStreamReader(in5)); Line 1380 Line 1380 // Must use DataInputStream for data: Line 1380 System.out.println(in5.readDouble()); Line 1380 // Can now use the "proper" readLine(): Line 1380 System.out.println(in5br.readLine()); Line 1380 } catch(EOFException e) { Line 1380 System.out.println("End of stream"); Line 1380 } Line 1380 Line 1380 } catch(FileNotFoundException e) { Line 1380 System.out.println( Line 1380 "File Not Found:" + args[1]); Line 1380 } catch(IOException e) { Line 1380 System.out.println("IO Exception"); Line 1380 } Line 1380 } Line 1380}