logging in or signing up GAJ_ACCPi7_SEMII_IO_S4 stormdt Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 18 Category: Education License: All Rights Reserved Like it (0) Dislike it (0) Added: March 22, 2010 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Java I/O : Java I/O Module Overview : Module Overview This module covers the java.io package that contains various classes known as Input/Output (I/O) streams. These streams manage the input and output operations to files, network connections and other I/O devices. The primary focus of this module is on how to perform I/O operations using these streams. In this module, you will learn about: Streams Datalnput and DataOutput interfaces InputStream class and its subclasses OutputStream class and its subclasses File Class Buffered Streams Character Streams Serialization #1 - Streams : #1 - Streams Define data streams. Identify the need for streams Describe the methods of PrintWriter class. Stream Classes : Stream Classes A data stream is a channel through which data travels from a source to a destination. The standard input/output stream in Java is represented by three fields of the System class: in out err Need for Stream Classes : Need for Stream Classes In Java, streams are required to perform all the input/output (I/O) operations. An input stream receives data from a source into a program An output stream sends data to a destination from the program. Thus, stream classes help in: Reading input from a stream. Writing output to a stream. Managing disk files. Share data with a network of computers Categories of streams in Java : Categories of streams in Java Byte Streams – Low-Level Stream Handle byte oriented input/output operations. InputStream and OutputStream classes are at the top of their hierarchy. Character Streams – High-Level Streams Handle character oriented input/output operations. They make use of Unicode and can be internationalized. #2 - Datalnput and DataOutput interfaces : #2 - Datalnput and DataOutput interfaces Describe DataInput interface and its methods Describe DataOutput interface and its methods “Datalnput" Interface : “Datalnput" Interface Reading bytes from a binary stream and convert the data to any of the Java primitive types. Converting data from Java modified Unicode Transmission Format (UTF)-8 format into string form. Methods of Datalnput interface : Methods of Datalnput interface Example of Using DataInput Interface : Example of Using DataInput Interface The DataOutput interface : The DataOutput interface Converting data present in Java primitive type into a series of bytes and write them onto a binary stream. Converting string data into Java-modified UTF-8 format and write it into a stream. Methods of DataOutput interface : Methods of DataOutput interface Example of Using DataOutput Interface : Example of Using DataOutput Interface #3 - "InputStream" class and its subclasses : #3 - "InputStream" class and its subclasses Explain the InputStream class. Describe the FilelnputStream class, its constructors and methods. Explain ByteArraylnputStream, its constructors and methods. “InputStream” abstract class : “InputStream” abstract class Define how streams receive data Super of all stream classes. Has method to read bytes or array of bytes, mark locations in the stream, find out number of bytes has been reads or available for reading and so on. Used to read data from an input stream. Methods of “InputStream” class : Methods of “InputStream” class FileInputStream class : FileInputStream class A FileInputStream obtains input bytes from a file in a file system. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. FilelnputStream class overrides all the methods of the InputStream class except mark() and reset() methods. Constructor of FileInputStream Class : Constructor of FileInputStream Class Methods of FileInputStream Class : Methods of FileInputStream Class Example of FileInputStream Class : Example of FileInputStream Class ByteArraylnputStream class : ByteArraylnputStream class Contains a buffer that stores the bytes that are read from the stream. ByteArraylnputStream class uses a byte array as the source. ByteArraylnputStream class has an internal counter, which keeps track of the next byte to be read. Example of ByteArraylnputStream class : Example of ByteArraylnputStream class #4 - "OutputStream" class and its subclasses : #4 - "OutputStream" class and its subclasses Explain OutputStream class. Explain FileOutputStream class and list its constructors and methods. Describe the ByteArrayOutputStream class, its constructors and methods. OutputStream abstract class : OutputStream abstract class Defines the method in which bytes or arrays of bytes are written to streams. Methods of “OutputStream” class : Methods of “OutputStream” class FileOutputStream class : FileOutputStream class Creates an OutputStream that is used to write bytes to a file. FileOutputstream may or may not create the file before opening it for output Depends on the underlying platform. An lOException will be thrown only when a read-only file is opened. Constructor of FileOutputStream Class : Constructor of FileOutputStream Class Methods of FileOutputStream Class : Methods of FileOutputStream Class Example of FileOutputStream Class : Example of FileOutputStream Class ByteArrayOutputStream class : ByteArrayOutputStream class Creates an output stream in which the data is written using a byte array. Allows the output array to grow in size so as to accommodate the new data that is written. The data can be retrieved using toByteArray() and toString(). Methods of ByteArrayOutputStream class : Methods of ByteArrayOutputStream class Example of ByteArrayOutputStream class : Example of ByteArrayOutputStream class #5 - "File" Class : #5 - "File" Class Identify the purpose of the File class, its constructors and methods. Identify the purpose of the FileDescriptor class, its constructor and methods. “File” class : “File” class Directly works with files and the file system. Provide methods for operation on file and directory. Allows to create, delete and rename files Provide access to the pathname of the file Determine whether any object is a file or directory Checks the read and write access permissions. Constructor of File class : Constructor of File class Methods of File class : Methods of File class FileDescriptor class : FileDescriptor class Provides access to the file descriptors that are maintained by the OS when files and directories are being accessed. Applications should not create their own file descriptors. Methods of FileDescriptor class : Methods of FileDescriptor class #6- Buffered Streams : #6- Buffered Streams Define buffered input and output. Describe the BufferedlnputStream class. Describe the BufferedOutputStream class. Buffered I/O : Buffered I/O A buffer is a temporary storage area for data. By storing data in a buffer, we save time as we immediately get it from the buffer instead of going back to the original source of data. Java uses buffered input and output to temporarily cache data, read from or written to a stream. Buffered I/O Class : Buffered I/O Class Low-Level Stream (Byte Streams) BufferedInputStream BufferedOutputStream Hi-Level Stream (Character Streams) BufferedReader BufferedWriter It is advisable to wrap a BufferedXXX around any Stream or Reader whose read() or write() operations may be costly. FileInputStream fis = new FileInputStream("test.dat"); BufferedInputStream bis = new BufferedInputStream(fis); Guide : Guide For reading/writing directly with byte data uses FileInputStream/FileOutputStream For reading/writing character data uses FileReader/FileWriter Use BufferedXXX for the efficient reading/writing data Example of Using Buffered I/O Class : Example of Using Buffered I/O Class #7 - Character Streams (High-Level Streams) : #7 - Character Streams (High-Level Streams) Describe Character Streams Explain the Reader and Writer classes Describe the PrintWriter class Describe the CharArrayReader class Describe the CharArrayWriter class. Character Streams : Character Streams Provide functionalities to handle character oriented I/O operations. They support Unicode characters and can be internationalized. Reader and Writer are abstract classes at the top of the class hierarchy All character stream class are derived from the Reader and Writer class. Reader abstract class : Reader abstract class Used for reading character streams. Methods of Reader class : Methods of Reader class “CharArrayReader" Class : “CharArrayReader" Class Subclass of Reader class. The class uses character array as the source of text to be read. "Writer“ abstract Classes : "Writer“ abstract Classes Supports writing characters into streams Methods of “Writer” class : Methods of “Writer” class “PrintWriter” class : “PrintWriter” class Subclass of Writer Useful for console output. “CharArrayWriter” class : “CharArrayWriter” class Subclass of Writer class. Uses a character array into which characters are written. Example of FileReader/FileWriter class : Example of FileReader/FileWriter class Example of PrintWriter/BufferedReader class : Example of PrintWriter/BufferedReader class Question ? : Question ? Now InputStream/OutputStream for handling byte stream. Reader/Wrtire for handling character stream. Is there any stream left? No, but there is a type of byte stream so-called Object Stream #8 - Serialization : #8 - Serialization Define Serialization and describe the need and purpose of Serialization. Outline the features and methods of the ObjectlnputStream class. Outline the features and methods of the ObjectOutputStream class. Serialization : Serialization The process of reading and writing objects to a byte stream. An object that implements the serializable interface will have its state saved and restored using serialization and deserialization facilities. If a superclass is serializable then its subclasses are also serializable. The only exception is if a variable is transient and static, its state cannot be saved by serialization facilities. Serialization is required to implement the Remote Method Invocation (RMI) Providing Object Serialization for Your Classes : Providing Object Serialization for Your Classes “ObjectlnputStream” class : “ObjectlnputStream” class Subclass of InputStream class Responsible for reading object instances and primitive types from an underlying input stream. Methods of “ObjectlnputStream” class : Methods of “ObjectlnputStream” class “ObjectOutputStream" Class : “ObjectOutputStream" Class Subclass of OutputStream class Responsible for writing primitive data types and object to the output stream. Methods of “ObjectOutputStream" Class : Methods of “ObjectOutputStream" Class Example of “ObjectOutputStream" ClassSave the object’s state to file : Example of “ObjectOutputStream" ClassSave the object’s state to file Example of “ObjectInputStream" ClassRead and rebuild the object from file : Example of “ObjectInputStream" ClassRead and rebuild the object from file That’s about all for today! : That’s about all for today! For I/O byte data uses: FileInputStream/FileOutputStream For I/O character data uses FileReader/FileWriter Use BufferedXXX for the efficient reading/writing data Thank you all for your attention and patient ! You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
GAJ_ACCPi7_SEMII_IO_S4 stormdt Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 18 Category: Education License: All Rights Reserved Like it (0) Dislike it (0) Added: March 22, 2010 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Java I/O : Java I/O Module Overview : Module Overview This module covers the java.io package that contains various classes known as Input/Output (I/O) streams. These streams manage the input and output operations to files, network connections and other I/O devices. The primary focus of this module is on how to perform I/O operations using these streams. In this module, you will learn about: Streams Datalnput and DataOutput interfaces InputStream class and its subclasses OutputStream class and its subclasses File Class Buffered Streams Character Streams Serialization #1 - Streams : #1 - Streams Define data streams. Identify the need for streams Describe the methods of PrintWriter class. Stream Classes : Stream Classes A data stream is a channel through which data travels from a source to a destination. The standard input/output stream in Java is represented by three fields of the System class: in out err Need for Stream Classes : Need for Stream Classes In Java, streams are required to perform all the input/output (I/O) operations. An input stream receives data from a source into a program An output stream sends data to a destination from the program. Thus, stream classes help in: Reading input from a stream. Writing output to a stream. Managing disk files. Share data with a network of computers Categories of streams in Java : Categories of streams in Java Byte Streams – Low-Level Stream Handle byte oriented input/output operations. InputStream and OutputStream classes are at the top of their hierarchy. Character Streams – High-Level Streams Handle character oriented input/output operations. They make use of Unicode and can be internationalized. #2 - Datalnput and DataOutput interfaces : #2 - Datalnput and DataOutput interfaces Describe DataInput interface and its methods Describe DataOutput interface and its methods “Datalnput" Interface : “Datalnput" Interface Reading bytes from a binary stream and convert the data to any of the Java primitive types. Converting data from Java modified Unicode Transmission Format (UTF)-8 format into string form. Methods of Datalnput interface : Methods of Datalnput interface Example of Using DataInput Interface : Example of Using DataInput Interface The DataOutput interface : The DataOutput interface Converting data present in Java primitive type into a series of bytes and write them onto a binary stream. Converting string data into Java-modified UTF-8 format and write it into a stream. Methods of DataOutput interface : Methods of DataOutput interface Example of Using DataOutput Interface : Example of Using DataOutput Interface #3 - "InputStream" class and its subclasses : #3 - "InputStream" class and its subclasses Explain the InputStream class. Describe the FilelnputStream class, its constructors and methods. Explain ByteArraylnputStream, its constructors and methods. “InputStream” abstract class : “InputStream” abstract class Define how streams receive data Super of all stream classes. Has method to read bytes or array of bytes, mark locations in the stream, find out number of bytes has been reads or available for reading and so on. Used to read data from an input stream. Methods of “InputStream” class : Methods of “InputStream” class FileInputStream class : FileInputStream class A FileInputStream obtains input bytes from a file in a file system. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. FilelnputStream class overrides all the methods of the InputStream class except mark() and reset() methods. Constructor of FileInputStream Class : Constructor of FileInputStream Class Methods of FileInputStream Class : Methods of FileInputStream Class Example of FileInputStream Class : Example of FileInputStream Class ByteArraylnputStream class : ByteArraylnputStream class Contains a buffer that stores the bytes that are read from the stream. ByteArraylnputStream class uses a byte array as the source. ByteArraylnputStream class has an internal counter, which keeps track of the next byte to be read. Example of ByteArraylnputStream class : Example of ByteArraylnputStream class #4 - "OutputStream" class and its subclasses : #4 - "OutputStream" class and its subclasses Explain OutputStream class. Explain FileOutputStream class and list its constructors and methods. Describe the ByteArrayOutputStream class, its constructors and methods. OutputStream abstract class : OutputStream abstract class Defines the method in which bytes or arrays of bytes are written to streams. Methods of “OutputStream” class : Methods of “OutputStream” class FileOutputStream class : FileOutputStream class Creates an OutputStream that is used to write bytes to a file. FileOutputstream may or may not create the file before opening it for output Depends on the underlying platform. An lOException will be thrown only when a read-only file is opened. Constructor of FileOutputStream Class : Constructor of FileOutputStream Class Methods of FileOutputStream Class : Methods of FileOutputStream Class Example of FileOutputStream Class : Example of FileOutputStream Class ByteArrayOutputStream class : ByteArrayOutputStream class Creates an output stream in which the data is written using a byte array. Allows the output array to grow in size so as to accommodate the new data that is written. The data can be retrieved using toByteArray() and toString(). Methods of ByteArrayOutputStream class : Methods of ByteArrayOutputStream class Example of ByteArrayOutputStream class : Example of ByteArrayOutputStream class #5 - "File" Class : #5 - "File" Class Identify the purpose of the File class, its constructors and methods. Identify the purpose of the FileDescriptor class, its constructor and methods. “File” class : “File” class Directly works with files and the file system. Provide methods for operation on file and directory. Allows to create, delete and rename files Provide access to the pathname of the file Determine whether any object is a file or directory Checks the read and write access permissions. Constructor of File class : Constructor of File class Methods of File class : Methods of File class FileDescriptor class : FileDescriptor class Provides access to the file descriptors that are maintained by the OS when files and directories are being accessed. Applications should not create their own file descriptors. Methods of FileDescriptor class : Methods of FileDescriptor class #6- Buffered Streams : #6- Buffered Streams Define buffered input and output. Describe the BufferedlnputStream class. Describe the BufferedOutputStream class. Buffered I/O : Buffered I/O A buffer is a temporary storage area for data. By storing data in a buffer, we save time as we immediately get it from the buffer instead of going back to the original source of data. Java uses buffered input and output to temporarily cache data, read from or written to a stream. Buffered I/O Class : Buffered I/O Class Low-Level Stream (Byte Streams) BufferedInputStream BufferedOutputStream Hi-Level Stream (Character Streams) BufferedReader BufferedWriter It is advisable to wrap a BufferedXXX around any Stream or Reader whose read() or write() operations may be costly. FileInputStream fis = new FileInputStream("test.dat"); BufferedInputStream bis = new BufferedInputStream(fis); Guide : Guide For reading/writing directly with byte data uses FileInputStream/FileOutputStream For reading/writing character data uses FileReader/FileWriter Use BufferedXXX for the efficient reading/writing data Example of Using Buffered I/O Class : Example of Using Buffered I/O Class #7 - Character Streams (High-Level Streams) : #7 - Character Streams (High-Level Streams) Describe Character Streams Explain the Reader and Writer classes Describe the PrintWriter class Describe the CharArrayReader class Describe the CharArrayWriter class. Character Streams : Character Streams Provide functionalities to handle character oriented I/O operations. They support Unicode characters and can be internationalized. Reader and Writer are abstract classes at the top of the class hierarchy All character stream class are derived from the Reader and Writer class. Reader abstract class : Reader abstract class Used for reading character streams. Methods of Reader class : Methods of Reader class “CharArrayReader" Class : “CharArrayReader" Class Subclass of Reader class. The class uses character array as the source of text to be read. "Writer“ abstract Classes : "Writer“ abstract Classes Supports writing characters into streams Methods of “Writer” class : Methods of “Writer” class “PrintWriter” class : “PrintWriter” class Subclass of Writer Useful for console output. “CharArrayWriter” class : “CharArrayWriter” class Subclass of Writer class. Uses a character array into which characters are written. Example of FileReader/FileWriter class : Example of FileReader/FileWriter class Example of PrintWriter/BufferedReader class : Example of PrintWriter/BufferedReader class Question ? : Question ? Now InputStream/OutputStream for handling byte stream. Reader/Wrtire for handling character stream. Is there any stream left? No, but there is a type of byte stream so-called Object Stream #8 - Serialization : #8 - Serialization Define Serialization and describe the need and purpose of Serialization. Outline the features and methods of the ObjectlnputStream class. Outline the features and methods of the ObjectOutputStream class. Serialization : Serialization The process of reading and writing objects to a byte stream. An object that implements the serializable interface will have its state saved and restored using serialization and deserialization facilities. If a superclass is serializable then its subclasses are also serializable. The only exception is if a variable is transient and static, its state cannot be saved by serialization facilities. Serialization is required to implement the Remote Method Invocation (RMI) Providing Object Serialization for Your Classes : Providing Object Serialization for Your Classes “ObjectlnputStream” class : “ObjectlnputStream” class Subclass of InputStream class Responsible for reading object instances and primitive types from an underlying input stream. Methods of “ObjectlnputStream” class : Methods of “ObjectlnputStream” class “ObjectOutputStream" Class : “ObjectOutputStream" Class Subclass of OutputStream class Responsible for writing primitive data types and object to the output stream. Methods of “ObjectOutputStream" Class : Methods of “ObjectOutputStream" Class Example of “ObjectOutputStream" ClassSave the object’s state to file : Example of “ObjectOutputStream" ClassSave the object’s state to file Example of “ObjectInputStream" ClassRead and rebuild the object from file : Example of “ObjectInputStream" ClassRead and rebuild the object from file That’s about all for today! : That’s about all for today! For I/O byte data uses: FileInputStream/FileOutputStream For I/O character data uses FileReader/FileWriter Use BufferedXXX for the efficient reading/writing data Thank you all for your attention and patient !