当前位置:网站首页>Day_ 18 IO stream system
Day_ 18 IO stream system
2022-07-03 19:04:00 【Love Siyi alone】
BufferedInputStream/BufferedOutputStream
BufferedInputStream/BufferedOutputStream : Efficient byte input stream / Efficient byte output stream -> Buffer flow
Open a in memory buffer , The data will be stored in the buffer first , When the buffer is full, it will be automatically refreshed to the target file
// This convection is only a little different when creating the flow object , The logic of reading and writing is the same !!
Construction method :
BufferedInputStream(InputStream in)
new BufferedInputStream(new FileInputStream(" Source file address "));// Packaging flow
BufferedOutputStream(OutputStream out)
new BufferedOutputStream(new FileOutputStream(" Destination file address "));// Packaging flow
Overview of character stream
There are a lot of character files in the computer , It is inconvenient to operate character files with byte stream !
Character file : It works windows The built-in Notepad doesn't open " The statement " The file of
Root node of character stream : Reader/Writer -> abstract class
Normal character stream : FileReader/FileWriter
Efficient character stream : BufferedReader/BufferedWriter
FileReader/FileWriter
Construction method :
FileReader -> FileReader(" Source file address ");
FileWriter -> FileWriter(" Destination file address ");/FileWriter(" Destination file address ", Add write switch );
How to read and write :
FileReader Read method :
* int read(): Read one character at a time
* int read(char[] chs) : Read one array at a time
int read(char[] chs,int offset,int length) : Read part of an array one at a time
FileWriter The method of writing :
*void write(int ch): Write one character at a time
void write(char[] chs): Write an array of characters one at a time
*void write(char[] chs,int offset,int length): Write part of a character array one at a time
*void write(String str): Write one string at a time
void write(String str,,int offset,int length): Write one part of a string at a time
BufferedReader/BufferedWriter
BufferedReader/BufferedWriter : Efficient character input stream / Efficient character output stream -> Buffer flow , Packaging flow
Construction method :
BufferedReader(Reader in)
new BufferedReader(new FileReader(" Source file address "));// Packaging flow
BufferedWriter(Writer out)
new BufferedWriter(new FileWriter(" Destination file address "));// Packaging flow
The basic reading and writing methods are the same as ordinary character streams !
BufferedReader/BufferedWriter The unique method of ( important )
BufferedReader Special reading methods :
String readLine() : Read one line of string at a time // But don't read the newline at the end of a line
To make up for it BufferedReader Can't read line breaks , BufferedWriter You need to write a line and a newline
// Because of the different operating systems , Line breaks are different : windows:\r\n Linux:\n MacOS: \r
BufferedWriter Provides a way to write line breaks according to different operating systems : void newLine()
Encoding and decoding
Everything in the computer is bytes ( Everything in the computer is bit (0,1 Binary system ))
code : Write binary code
written words -- Coding format --> Binary code
decode : Parse binary code
Binary code -- Coding format --> written words
Why are files garbled : The encoding and decoding methods are different !!
Solve the mess : Ensure that the encoding format used in encoding and decoding is consistent !!
Ways to recommend : Manually change the encoding format of the document
Don't change the coding format of the platform
Try not to change with code
Encoding and decoding methods in strings
String --> Binary code (byte[]) ( code )
byte[] getBytes(): Encode the string content according to the default encoding format of the platform (byte[])
byte[] getBytes(String charsetName): Encode the string contents according to the specified encoding format (byte[])
Binary code --> String ( decode )
String(byte[] bytes) : Decode the byte array according to the default encoding format of the platform
String(byte[] bytes, int offset, int length) : Decode part of the contents of the byte array according to the default encoding format of the platform
// Decode the byte array according to the specified encoding format !
String(byte[] bytes, String charsetName)
String(byte[] bytes, int offset, int length, String charsetName)
Character set
Character set Is the general name of coding format ( There are multiple coding tables in a character set )
The most basic coding table : ASCII surface -> A character takes up a byte
Common character sets :
GB series : Chinese character set
GB2312
GBK: The current popular Chinese coding table -> A Chinese character takes up two bytes
Unicode : The standard character set on the Internet
UTF-8 : Internet default coding table -> One Chinese character takes up three bytes
UTF-16
UTF-32
Encoding table : ISO-8859-1 Latin code
InputStreamReader/OutputStreamWriter
InputStreamReader/OutputStreamWriter : Converted flow
characteristic :
1. A bridge between byte flow and character flow
2. Set the time for reading and writing Coding format -> The file is read and written according to the coding format !!
Construction method :
InputStreamReader(InputStream in) : Transfer byte input into character input stream , According to the default encoding format of the platform ;
OutputStreamWriter(OutputStream out) : Transfer byte output to character output stream , According to the default encoding format of the platform ;
--------------------------------------
// Character stream = Byte stream + Coding format ;
InputStreamReader(InputStream in, String charsetName) : According to the specified encoding format ;
OutputStreamWriter(OutputStream out, String charsetName) : According to the specified encoding format ;
Reading and writing methods : InputStreamReader/OutputStreamWriter yes Reader/Writer Subclasses of
read : Three ways of reading
Write : Five ways of writing
System.in/System.out
System Class :
System.in: Standard system input -> Byte stream (InputStream) -> Only do keyboard entry Source : keyboard
System.out: Standard system output -> Byte stream (PrintStream) -> Only do print console The goal is : Console
ObjectInputStream/ObjectOutputStream
serialize : Permanent storage
ObjectInputStream/ObjectOutputStream : Deserialize stream / Serialization flow ( Object input stream / Object output stream )
Construction method : Packaging flow
ObjectInputStream(InputStream in)
ObjectOutputStream(OutputStream out)
Conventional reading and writing methods : Like all byte streams
Three ways of reading , Three ways of writing
Special reading and writing methods : Read object / Write about
ObjectInputStream : Object readObject(): Read an object from the object file
ObjectOutputStream : void writeObject(Object obj): Write an object to the serialization file
matters needing attention :
1. If you want to write objects to a file , The class of the object must be required to implement Serializable Interface !!
2. The rule is : Load all objects into the set before writing objects Write the collection object to the file Write once !!
Set automatic generation VersionUID

Standard procedure for customizing description classes ( a key )
1 Private all member variables
2 Automatically generate parameterless constructs
3 Automatically generate all parameter constructs
4 Automatic generation getter and setter Method
5 Automatic generation equals and hashCode Method
6 Automatic generation toString Method
7 implements Serializable Serializable
8 Automatically generate serialization id
// Behavior of objects Write on demand
边栏推荐
- 利用可视化结果,点击出现对应的句子
- Dart JSON编码器和解码器剖析
- 简述服务量化分析体系
- Typescript configuration
- Unity webgl optimization
- [Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
- __ Weak and__ The difference between blocks
- Differential constrained SPFA
- 组策略中开机脚本与登录脚本所使用的用户身份
- Max of PHP FPM_ Some misunderstandings of children
猜你喜欢

Su embedded training - Day10

我们做了一个智能零售结算平台
![[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)](/img/4e/a51365bb88b1fc29d1c77fcdde5350.jpg)
[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)

There are several levels of personal income tax

Driveseg: dynamic driving scene segmentation data set

Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)

Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement

Smart wax therapy machine based on STM32 and smart cloud

Raft log replication

Does SQL always report foreign key errors when creating tables?
随机推荐
Scrape crawler framework
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
简述服务量化分析体系
There are several levels of personal income tax
Unity2018 to wechat games without pictures
硬盘监控和分析工具:Smartctl
php-fpm的max_chindren的一些误区
Processing of user input parameters in shell script
Smart wax therapy machine based on STM32 and smart cloud
Work Measurement - 1
Find the median of two positive arrays
Boost.Asio Library
我们做了一个智能零售结算平台
虚拟机和开发板互Ping问题
Zero length array
Multifunctional web file manager filestash
KINGS
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
High concurrency Architecture - separate databases and tables