1, IO style
Used to manipulate file content
The content structure is as follows:
Note: When using byte streams, pay attention to the return value of the read method.
If a single byte is read, the return is the corresponding ASCII code value.
If the array is read, then the return is the number of bytes read.
If the return value is -1 means the end of the file,
only the character stream can be used directly
The reason for the garbled code is that the encoding format used in the file storage is inconsistent with the encoding format used in the io stream.
2. The difference between byte stream and character stream
The same point: they are all io streams, used to manipulate file content
Difference: different units of operation
Byte stream: read or write data based on bytes. It is mostly used to manipulate media resources, audio, video, pictures, files, and encoding sets. It is possible to generate garbled
character streams: based on characters As a unit, read or write data, mostly used to manipulate text files
When outputting: byte stream from memory-"disk, data can be written without closing the stream; when character stream is written from memory-"buffer -" disk, you need to manually refresh or close the stream to write the buffer data To disk
3. Exception handling
Appeared after jdk1.7; the syntax is
try(
//需要关闭的流资源
){
//功能语句
}catch(//异常对象){
//异常处理
}