当前位置:网站首页>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
边栏推荐
- [proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
- Smart wax therapy machine based on STM32 and smart cloud
- Multifunctional web file manager filestash
- Php based campus lost and found platform (automatic matching push)
- PyTorch中在反向传播前为什么要手动将梯度清零?
- 【光学】基于matlab介电常数计算【含Matlab源码 1926期】
- What does a really excellent CTO look like in my eyes
- How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?
- The more you talk, the more your stupidity will be exposed.
- EGO Planner代碼解析bspline_optimizer部分(1)
猜你喜欢

Record: pymysql is used in pycharm to connect to the database

Getting started with JDBC
![leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]](/img/d4/cbbaec40119be6cb5594899e348261.png)
leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]

Why should we do feature normalization / standardization?
![leetcode:556. Next larger element III [simulation + change as little as possible]](/img/a0/12e5ee5d01d666acb4b75ada2e6fec.png)
leetcode:556. Next larger element III [simulation + change as little as possible]

leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】

【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
![[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]](/img/cb/ee696d5a7d6bef96fe0db89e8478ed.jpg)
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]

东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会

Compose LazyColumn 顶部添加控件
随机推荐
Understanding of database architecture
High concurrency Architecture - distributed search engine (ES)
SQL custom collation
Php based campus lost and found platform (automatic matching push)
FBI warning: some people use AI to disguise themselves as others for remote interview
Which do MySQL and Oracle learn?
High concurrency architecture cache
php-fpm的max_chindren的一些误区
平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
Ego planner code parsing Bspline_ Optimizer section (3)
[Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
Webrtc[41] - Analysis of the establishment process of webrtc transmission channel
EGO Planner代码解析bspline_optimizer部分(2)
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
【LeetCode】【SQL】刷题笔记
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Record: install MySQL on ubuntu18.04
What is the function of registering DLLs- What does registering a DLL do?
Zhengda futures news: soaring oil prices may continue to push up global inflation
Help change the socket position of PCB part