This is the fourth day of my participation in Gwen Challenge

Use of the File class

  1. An object of the File class that represents a File or a folder directory
  2. The File class is declared in the java.io package
  3. File class involves the creation, deletion, renaming, modification time, File size and other methods of files or File directories. There is no operation to write or read the contents of the file. If you need to implement these functions, you must use IO streams to do so.
  4. Subsequent objects of the File class are often passed as arguments to the stream’s constructor, indicating the “end point” of reading or writing

IO flow principle and flow classification

  • Data unit: byte stream, character stream
  • Data flow direction: input flow, output flow
  • The role of flow: node flow, processing flow

Flow architecture

Object flow:

The ObjectOutputStream and ObjectInputStream

Function:

  • ObjectInputStream: objects in memory —-> Files in storage, sent out over the network: serialization process
  • ObjectOutputStream: files in storage, sent out over the network — > Objects in memory: deserialization process

Buffer flow:

Function: Provides the read and write speed of a stream

Reason for improved read/write speed: Internal provides a buffer

Process streams by nesting them on top of existing streams.

Conversion flow of processing flow:

  • InputStreamReader
  • OutputStreamWriter

Conversion streams provide conversion between byte streams and character streams

  1. Belong to character stream
  2. Function: Provides conversion between byte stream and character stream
  3. Decoding: byte, byte array -> character array, string encoding: character array, string -> byte, byte array

Serialization, deserialization

Purpose: A processing stream used to store and read data or objects of a primitive data type. Its power lies in the ability to write objects from Java to and from the data source.

Serialization mechanism: Allows Java objects in memory to be converted into platform-independent binary streams, which allow such binary streams to be persisted on disk or transferred over the network to another network node

Deserialization: When other programs acquire this binary stream, they can revert to the original Java objects

For an object to be serializable, there are several requirements:

  1. Implementation interface: Serializable identifies the interface
  2. The class of the object provides a constant: the sequence version number
  3. Require that the properties of the object also be serializable. (Base data types are themselves serializable)