Course review:
Flow: A conduit for data communication
Common Stream classes:
1. File stream: File: Data in Files
1, FileInputStream
2, FileOutputStream
3, FileReader
4, FileWriter
2. Memory stream: ByteArray: Data in memory (array)
1, Bytearrayinputstream
2, Bytearrayoutputstream
3. Buffer stream: Buffered: Improve reading and writing efficiency
1, Bufferedinputstream
2, Bufferedoutputstream
3, BufferedReader
ReadLine
4, BufferedWriter
NewLine
Today's content:
Common Stream classes:
1. File stream: File: Data in Files
1, FileInputStream
2, FileOutputStream
3, FileReader
4, FileWriter
2. Memory stream: ByteArray: Data in memory (array)
1, Bytearrayinputstream
2, Bytearrayoutputstream
3. Buffer stream: Buffered: Improve reading and writing efficiency
1, Bufferedinputstream
2, Bufferedoutputstream
3, BufferedReader
ReadLine
4, BufferedWriter
NewLine
4. Conversion stream: Used for conversion between byte stream and character stream, can specify encoding format, process stream, character stream
1. OutputStreamWriter: Convert output character stream
Output character stream----output byte stream
Common methods:
Write: Write, character
Flush: Refresh
2. InputStreamReader: convert input character stream
Input byte stream-----"input character stream"
Common methods:
Read
Skip
5. Object flow: Can write (serialize) or read (deserialize) data of various data types
byte stream, processing flow
Serialization: The process of encoding related information about the corresponding class and related content of the object (transient, static will not participate in serialization)
Deserialization: Parsing serialized content
1. ObjectOutputStream: Object Output byte stream
Saving data in a serialized format
Common methods:
WriteXXX: Write data of different data types
WriteObject: Writing objects
Wirteutf: Writing out a string
2. ObjectInputStream: Object input byte stream
To deserialize data into a read
Common methods:
READXXX: Reading data of the specified type
ReadObject: Reading an Object
readUTF: Reading a string
The object flow must remember the following two points when used:
1. Object flow can only appear in pairs (using the object output stream you must also use the object input stream to read the data)
2, the reading and writing order must be consistent (how to write on how to read)
Writeint----->readint
Object stream read to end of file throws Eofexception exception
Eofexception exception is thrown when the number of bytes read exceeds the number of bytes remaining in the file
Property does not participate in the serialization method:
1. Static: Statics
Static properties do not participate in serialization
2, transient: transient
Decorated properties are not involved in serialization
When a custom class is serialized, the corresponding class must implement the serializable (serialized interface)
6. Print Flow: Print data of various data types, process flow
Output only, no input
1. PrintStream: Print byte stream
Common methods:
Print: Output various types of data
PRINTLN: Outputs various types of data, and writes out line breaks
Write: Write, byte
2. PrintWriter: Print character stream
Common methods:
Print: Output various types of data
PRINTLN: Outputs various types of data, and writes out line breaks
Write: Write, character
Three major criteria (redirect):
1. Standard input stream (InputStream)
System.in: Default data from keyboard input
If the data comes from the keyboard, it will not be read at the end of the file because the last Read method will block
System.setin: RESET data source for standard input
2. Standard output stream (PrintStream)
System.out: Data is output to the console by default
System.setout: Reset the standard output location
3. Standard error Stream (PrintStream)
System.err: Default data output to console (font red)
System.seterr: Reset the standard error stream location
7. Data Flow:
1, DataInputStream
2, DataOutputStream
8, Random Read file class:
"The Qianfengday19-java of the game" Basic Learning: conversion flow, object flow, print flow, three standards (redirect)