SlideShare a Scribd company logo
1 of 268
Chapter 19  Binary Input & Output   Java I  ITP 120
Chapter  Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview  ---  Streams ,[object Object]
2 Types of Stream Classes:  Bytes & Characters ,[object Object],[object Object],[object Object],[object Object]
Byte Stream Classes  (note: the word “stream” )
Character Stream Classes  (Character = 2 bytes)
How is I/O Handled in Java? ,[object Object],Formatter output = new Formatter("temp.txt"); output.format("%s", "Java 101"); output.close(); Scanner input = new Scanner(new File("temp.txt")); System.out.println(input.nextLine());
Text Files vs. Binary Files ,[object Object],[object Object]
Binary I/O ,[object Object]
Binary I/O Classes
[object Object],InputStream
[object Object],OutputStream
FileInputStream/FileOutputStream ,[object Object]
FileInputStream ,[object Object],[object Object],[object Object],[object Object]
FileOutputStream ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],TestFileStream Run
FilterInputStream/FilterOutputStream ,[object Object]
DataInputStream/DataOutputStream ,[object Object],DataOutputStream  converts primitive type values or strings into bytes and output the bytes to the stream.
DataInputStream DataInputStream  extends  FilterInputStream  and implements the  DataInput  interface.
DataOutputStream DataOutputStream  extends  FilterOutputStream  and implements the  DataOutput  interface.
Characters and Strings in Binary I/O   ,[object Object],Why UTF-8? What is UTF-8? UTF-8 is a coding scheme that allows systems to operate with both ASCII and Unicode efficiently. Most operating systems use ASCII. Java uses Unicode. The ASCII character set is a subset of the Unicode character set. Since most applications need only the ASCII character set, it is a waste to represent an 8-bit ASCII character as a 16-bit Unicode character. The UTF-8 is an alternative scheme that stores a character using 1, 2, or 3 bytes. ASCII values (less than 0x7F) are coded in one byte. Unicode values less than 0x7FF are coded in two bytes. Other Unicode values are coded in three bytes.
Using  DataInputStream / DataOutputStream   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],TestDataStream Run
Checking End of File ,[object Object],Order and Format CAUTION: You have to read the data in the same order and same format in which they are stored. For example, since names are written in UTF-8 using  writeUTF , you must read names using  readUTF .
BufferedInputStream/ BufferedOutputStream ,[object Object],BufferedInputStream / BufferedOutputStream  does not contain new methods. All the methods  BufferedInputStream / BufferedOutputStream  are inherited from the  InputStream / OutputStream  classes.
Constructing  BufferedInputStream / BufferedOutputStream   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Case Studies: Copy File  ,[object Object],[object Object],[object Object],[object Object],Copy Run
Object I/O ,[object Object],Optional
ObjectInputStream ,[object Object]
ObjectOutputStream ,[object Object]
Using Object Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],TestObjectOutputStream Run TestObjectInputStream Run
Random Access Files ,[object Object]
RandomAccessFile
File Pointer ,[object Object]
RandomAccessFile  Methods ,[object Object]
RandomAccessFile  Methods, cont. ,[object Object],[object Object],[object Object],[object Object]
RandomAccessFile  Methods, cont. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
RandomAccessFile  Constructor ,[object Object],[object Object]
Case Studies: Address Book ,[object Object],Optional
Fixed Length String I/O ,[object Object],FixedLengthStringIO
End of Presentation Binary Input & Output   Chapter 18
How is I/O Handled in Java? ,[object Object],Formatter output = new Formatter(“outfile.txt"); output.format("%s", "Java 120");  // Write a string to outfile.txt output.close();  // Close the output file  outfile.txt Scanner input = new Scanner(new File("temp.txt"));  // Create object System.out.println(input.nextLine());  // Read a line
Text Files vs. Binary Files ,[object Object],[object Object]
Binary File I/O ,[object Object]
Binary I/O Classes  Inheritance Hierarchy
[object Object],InputStream (a byte stream class)
[object Object],OutputStream ( a byte stream class)
FileInputStream & FileOutputStream (byte streams) ,[object Object]
FileInputStream (byte stream) ,[object Object],[object Object],[object Object],[object Object],[object Object]
FileOutputStream (byte stream) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FilterInputStream/FilterOutputStream ,[object Object]
DataInputStream & DataOutputStream (byte streams) ,[object Object],DataOutputStream  converts primitive type values or strings into bytes and outputs the bytes to the stream.
DataInputStream ( byte stream) DataInputStream  extends  FilterInputStream  and implements the  DataInput  interface.
DataOutputStream (byte stream) DataOutputStream  extends  FilterOutputStream  and implements the  DataOutput  interface.
Characters and Strings in Binary I/O   ,[object Object],What  is  UTF-8 ?  Why use UTF-8 ?  [  UTF  means Unicode Text File ] UTF-8 is a coding scheme that allows systems to operate with both ASCII and Unicode efficiently. Most operating systems use ASCII. Java uses Unicode. The ASCII character set is a subset of the Unicode character set. Since most applications need only the ASCII character set, it is a waste to represent an 8-bit ASCII character as a 16-bit Unicode character. The UTF-8 is an alternative scheme that stores a character using 1, 2, or 3 bytes. ASCII values (less than 0x7F) (127 decimal) are coded in one byte. Unicode values less than 0x7FF are coded in two bytes. Other Unicode values are coded in  three  bytes.
Using  DataInputStream / DataOutputStream   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Checking for the End of File (EOF) ,[object Object],Order and Format CAUTION: You have to read the data in the same order and same format in which they are stored. For example, if names are written in UTF-8 using  writeUTF (String  str) , you  MUST  read the names using the  readUTF  method.
BufferedInputStream/ BufferedOutputStream ,[object Object],BufferedInputStream / BufferedOutputStream  does not contain new methods. All the methods  BufferedInputStream / BufferedOutputStream  are inherited from the  InputStream / OutputStream  classes.
Constructing  BufferedInputStream / BufferedOutputStream   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CopyFile.java ,[object Object],[object Object],[object Object],[object Object],[object Object]
Object I/O  (optional) ,[object Object]
ObjectInputStream (optional) ,[object Object]
ObjectOutputStream (optional) ,[object Object]
Using Object Streams (optional) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  Serializable  Interface ,[object Object],[object Object],[object Object]
The  transient  Keyword ,[object Object],[object Object]
The  transient  Keyword, cont. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Serializing Arrays (optional)   ,[object Object],[object Object],[object Object]
Random Access Files ,[object Object],[object Object]
RandomAccessFile
File Pointers ,[object Object]
File Pointers  (moving the pointer 4 bytes ahead)
RandomAccessFile   Methods ,[object Object],[object Object],[object Object],[object Object]
RandomAccessFile   Methods, cont. ,[object Object],[object Object],[object Object],[object Object]
RandomAccessFile   Methods, cont. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
RandomAccessFile  Constructors ,[object Object],[object Object],[object Object],[object Object]
Case Study: Address Book ,[object Object],[object Object]
Fixed Length String I/O ,[object Object],FixedLengthStringIO
Chapter 18 Demo Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter 18 Demo Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter 18 Demo Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter 18  Demo Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter 18  Input / Output  Optional: More on Java File I/O   Chapter 18  Java I  ITP 120
Chapter 18:  More on Input and Output  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chapter 18  Input /Output  Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview  Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Overview  ---  Streams ,[object Object]
Overview and Background ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How is I/O Handled in Java? ,[object Object],Formatter output = new Formatter("temp.txt"); output.format("%s", "Java  ITP 120"); output.close(); Scanner input = new Scanner(new File("temp.txt")); System.out.println(input.nextLine());
Text Files vs. Binary Files ,[object Object],[object Object],[object Object]
Binary I/O ,[object Object]
2 Types of Stream Classes:  Bytes & Characters ,[object Object],[object Object],[object Object],[object Object]
Byte Stream Classes  (note: “stream” )
Character Stream Classes  (Character = 2 bytes)
Predefined Streams in Java ,[object Object],[object Object],[object Object],[object Object],[object Object]
Predefined Streams in Java:  System class ,[object Object],[object Object],[object Object],[object Object]
Predefined Streams in Java:  System class ,[object Object],[object Object],[object Object],[object Object],[object Object]
Reading Keyboard Input ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading Keyboard Input  ,[object Object],[object Object],[object Object],[object Object]
Writing Output to the Monitor ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stream classes  (Bytes & Characters) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stream Classes ,[object Object],[object Object],[object Object],[object Object]
InputStream Class  (for reading bytes) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
InputStream Class  (for reading bytes) ,[object Object],[object Object],[object Object],[object Object],[object Object]
InputStream Class  (for reading bytes) ,[object Object],[object Object],[object Object]
Reading & Writing Files Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Files Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Files Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Files Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writing to a File Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writing to a File Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writing to a File Using Byte Streams try {  // outer try block //  try to open input file  try {  // inner try fin = new FileInputStream(args[0]);  } catch(FileNotFoundException exc) {  System.out.println(“Error:”  +  exc.getMessage( ) ); System.out.println("Input File Not Found");  return;  }
Writing to a File Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writing to a File Using Byte Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data  Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reading & Writing Binary Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reader  class methods for reading  characters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
OutputStream ( bytes) & Writer (for characters) ,[object Object],[object Object],[object Object],[object Object]
OutputStream  (Writing bytes) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writer  (Writing characters)  (Same as OutputStream) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Input using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console  Output  using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Output using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Console Output using Character Streams ,[object Object],[object Object],[object Object],[object Object]
Console Output using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Console Output using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File Input & Output using Character Streams ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileWriter ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileWriter ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileWriter ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileReader ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileReader ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I / O using Character Streams  FileReader ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The File Class: Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The File Class ,[object Object],[object Object]
Obtaining file properties and manipulating file
Example  Using the File Class  TestFileClass.java Objective: Write a program that demonstrates how to create files in a platform-independent way and use the methods in the File class to obtain their properties. Figure 1 shows a sample run of the program on Windows, and Figure 2 a sample run on Unix  (Windows) (Unix)
The File Class and Processing External Files ,[object Object],[object Object],[object Object],[object Object]
The File Class and Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The File Class and Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demo Program:  TestFileClass.java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demo Program:  TestFileClass.java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files ,[object Object],[object Object],[object Object]
File I/O Stream Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File I/O Stream Constructors ,[object Object],FileInputStream infile = new FileInputStream("in.dat"); FileOutputStream outfile = new FileOutputStream("out.dat"); FileReader infile = new FileReader("in.dat"); FileWriter outfile = new FileWriter("out.dat");
Demo Program:  TestFileReader.java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demo Program:  TestFileReader.java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demo Program: TestFileWriter.java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files
Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files  if (args.length !=2)  // args[0] is source file {    // args[1]  is target file System.out.println( "Usage: java CopyFileUsingByteStream  f1  f2"); System.exit(0);  // Stop the program }
Processing External Files  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Processing External Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Filter Streams ,[object Object],[object Object],[object Object],[object Object]
Filter Streams ,[object Object],[object Object]
FilterInputStream  subclasses ,[object Object],[object Object],[object Object],[object Object]
FilterOutputStream  subclasses ,[object Object],[object Object],[object Object]
Data Streams  (bytes) ,[object Object],[object Object],[object Object],[object Object],[object Object]
DataInputStream Methods defined in the DataInput Interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DataOutputStream Methods   defined in the DataOutput   interface   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DataInputStream & DataOutput Stream  Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo  Example  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo  Example  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo  Example  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo  Example  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Data Streams  Demo  Example  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Character Classes  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Java I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Java I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Java I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Java I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Java I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Print Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Print Streams:   PrintWriter  Constructors ,[object Object],[object Object],[object Object],[object Object]
Print Streams:  PrintWriter   Methods  (for chars) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Print Streams:  PrintWriter  Methods ,[object Object],[object Object],[object Object],[object Object],[object Object]
Demo Program Example Using Print Streams ,[object Object],[object Object],[object Object],[object Object],[object Object]
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output

More Related Content

What's hot

IO In Java
IO In JavaIO In Java
IO In Javaparag
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47myrajendra
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in javaJayasankarPR2
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49myrajendra
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.ioNilaNila16
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52myrajendra
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)Om Ganesh
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51myrajendra
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and filesMarcello Thiry
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/ONem Sothea
 

What's hot (20)

IO In Java
IO In JavaIO In Java
IO In Java
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Java IO
Java IOJava IO
Java IO
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
 
Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
File Handling
File HandlingFile Handling
File Handling
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
Data file handling
Data file handlingData file handling
Data file handling
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
Files in java
Files in javaFiles in java
Files in java
 

Viewers also liked

Viewers also liked (20)

I/O in java Part 1
I/O in java Part 1I/O in java Part 1
I/O in java Part 1
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Java I/O
Java I/OJava I/O
Java I/O
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
Perl Development
Perl DevelopmentPerl Development
Perl Development
 
01 Ajax Intro
01 Ajax Intro01 Ajax Intro
01 Ajax Intro
 
Nosql availability & integrity
Nosql availability & integrityNosql availability & integrity
Nosql availability & integrity
 
Introduction To Silverlight and Prism
Introduction To Silverlight and PrismIntroduction To Silverlight and Prism
Introduction To Silverlight and Prism
 
Java swing
Java swingJava swing
Java swing
 
Forms authentication
Forms authenticationForms authentication
Forms authentication
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
PyCologne
PyColognePyCologne
PyCologne
 
Oid structure
Oid structureOid structure
Oid structure
 
5 Key Components of Genrocket
5 Key Components of Genrocket5 Key Components of Genrocket
5 Key Components of Genrocket
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Ajax & ASP.NET 2
Ajax & ASP.NET 2Ajax & ASP.NET 2
Ajax & ASP.NET 2
 
Oracle 10g Application Server
Oracle 10g Application ServerOracle 10g Application Server
Oracle 10g Application Server
 
Java/Swing
Java/SwingJava/Swing
Java/Swing
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Csc153 chapter 02
Csc153 chapter 02Csc153 chapter 02
Csc153 chapter 02
 

Similar to Itp 120 Chapt 19 2009 Binary Input & Output

UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesSakkaravarthiS1
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptxssuser9d7049
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3sotlsoc
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptxRathanMB
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxSadhilAggarwal
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2Gera Paulos
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and outputRiccardo Cardin
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfhemanth248901
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docx
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docxBINARY IOObjectivesCHAPTER 19■ To discover how IO .docx
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docxhartrobert670
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6Berk Soysal
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsDon Bosco BSIT
 

Similar to Itp 120 Chapt 19 2009 Binary Input & Output (20)

Io Streams
Io StreamsIo Streams
Io Streams
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
 
Io streams
Io streamsIo streams
Io streams
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdf
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docx
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docxBINARY IOObjectivesCHAPTER 19■ To discover how IO .docx
BINARY IOObjectivesCHAPTER 19■ To discover how IO .docx
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
 
Jedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io StreamsJedi Slides Intro2 Chapter12 Advanced Io Streams
Jedi Slides Intro2 Chapter12 Advanced Io Streams
 

More from phanleson

Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Sparkphanleson
 
Firewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth FirewallsFirewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth Firewallsphanleson
 
Mobile Security - Wireless hacking
Mobile Security - Wireless hackingMobile Security - Wireless hacking
Mobile Security - Wireless hackingphanleson
 
Authentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless ProtocolsAuthentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless Protocolsphanleson
 
E-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server AttacksE-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server Attacksphanleson
 
Hacking web applications
Hacking web applicationsHacking web applications
Hacking web applicationsphanleson
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designphanleson
 
HBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - OperationsHBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - Operationsphanleson
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBasephanleson
 
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibLearning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibphanleson
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streamingphanleson
 
Learning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLLearning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLphanleson
 
Learning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a ClusterLearning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a Clusterphanleson
 
Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programmingphanleson
 
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your DataLearning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your Dataphanleson
 
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value PairsLearning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value Pairsphanleson
 
Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Sparkphanleson
 
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about LibertagiaHướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagiaphanleson
 
Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLphanleson
 
Lecture 4 - Adding XTHML for the Web
Lecture  4 - Adding XTHML for the WebLecture  4 - Adding XTHML for the Web
Lecture 4 - Adding XTHML for the Webphanleson
 

More from phanleson (20)

Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Firewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth FirewallsFirewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth Firewalls
 
Mobile Security - Wireless hacking
Mobile Security - Wireless hackingMobile Security - Wireless hacking
Mobile Security - Wireless hacking
 
Authentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless ProtocolsAuthentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless Protocols
 
E-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server AttacksE-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server Attacks
 
Hacking web applications
Hacking web applicationsHacking web applications
Hacking web applications
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
 
HBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - OperationsHBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - Operations
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBase
 
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibLearning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlib
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streaming
 
Learning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLLearning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQL
 
Learning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a ClusterLearning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a Cluster
 
Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programming
 
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your DataLearning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your Data
 
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value PairsLearning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value Pairs
 
Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about LibertagiaHướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
 
Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XML
 
Lecture 4 - Adding XTHML for the Web
Lecture  4 - Adding XTHML for the WebLecture  4 - Adding XTHML for the Web
Lecture 4 - Adding XTHML for the Web
 

Itp 120 Chapt 19 2009 Binary Input & Output

  • 1. Chapter 19 Binary Input & Output Java I ITP 120
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Byte Stream Classes (note: the word “stream” )
  • 7. Character Stream Classes (Character = 2 bytes)
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. DataInputStream DataInputStream extends FilterInputStream and implements the DataInput interface.
  • 20. DataOutputStream DataOutputStream extends FilterOutputStream and implements the DataOutput interface.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40. End of Presentation Binary Input & Output Chapter 18
  • 41.
  • 42.
  • 43.
  • 44. Binary I/O Classes Inheritance Hierarchy
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. DataInputStream ( byte stream) DataInputStream extends FilterInputStream and implements the DataInput interface.
  • 53. DataOutputStream (byte stream) DataOutputStream extends FilterOutputStream and implements the DataOutput interface.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 70.
  • 71. File Pointers (moving the pointer 4 bytes ahead)
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82. Chapter 18 Input / Output Optional: More on Java File I/O Chapter 18 Java I ITP 120
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93. Byte Stream Classes (note: “stream” )
  • 94. Character Stream Classes (Character = 2 bytes)
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112. Writing to a File Using Byte Streams try { // outer try block // try to open input file try { // inner try fin = new FileInputStream(args[0]); } catch(FileNotFoundException exc) { System.out.println(“Error:” + exc.getMessage( ) ); System.out.println("Input File Not Found"); return; }
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157. Obtaining file properties and manipulating file
  • 158. Example Using the File Class TestFileClass.java Objective: Write a program that demonstrates how to create files in a platform-independent way and use the methods in the File class to obtain their properties. Figure 1 shows a sample run of the program on Windows, and Figure 2 a sample run on Unix (Windows) (Unix)
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 171.
  • 172.
  • 173. Processing External Files if (args.length !=2) // args[0] is source file { // args[1] is target file System.out.println( "Usage: java CopyFileUsingByteStream f1 f2"); System.exit(0); // Stop the program }
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.