This is the fourth day of my participation in Gwen Challenge
Use of the File class
- An object of the File class that represents a File or a folder directory
- The File class is declared in the java.io package
- 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.
- 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
- Belong to character stream
- Function: Provides conversion between byte stream and character stream
- 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:
- Implementation interface: Serializable identifies the interface
- The class of the object provides a constant: the sequence version number
- Require that the properties of the object also be serializable. (Base data types are themselves serializable)