当前位置:网站首页>Summary of I / O knowledge points
Summary of I / O knowledge points
2022-04-23 02:04:00 【Fu Sheng Ruo Meng 521】
| I/O Flow of knowledge | ||
| ·I/O The basic concept of | ||
| ·I/O Application of stream knowledge | ||
| · A practical example | ||
| Basic knowledge of , What is flow | ||
| · Simply speaking , Stream is a unified management of data input and output . | ||
| · The system helps us define how to write the contents of the stream to different external devices , When programming , All we need to consider is how to write the data in memory to the stream | ||
| · Determination of the direction of flow : | ||
| The reference is our own memory space | ||
| · Output stream :FileOutputStream, Is to store memory space data Write To external devices | ||
| · Input stream :FileInputStream, Is to transfer external data read Into memory . | ||
| · The output stream is write | ||
| · The read stream is the input stream | ||
| The type of flow | ||
| · Character stream , Is to transmit in character units , Character streams can be processed directly Unicode But it can only handle characters or strings | ||
| · Byte stream , Is to transmit in bytes , Byte stream can be used for any object , But you can't deal with it directly Unicode character | ||
| When to use what stream | ||
| · If you're dealing with plain text , Then use the character stream | ||
| · If it's dealing with pictures 、 Video etc. , Then use byte stream | ||
| Byte stream | ||
| · Byte stream operations are inherited from abstract classes | ||
| InputStream And OutputStream | ||
| · Generally, you can operate on files , Will use | ||
| FileInoutStream And FileOutputStream | ||
| ·FileIutputStream Input stream | ||
| String path = "D:/test.txt"; | ||
| File file = new Path(); | ||
| FileInputStream fis = new FileInputStream(file); | ||
| if(!file.exists()){ | ||
| // If not, create a file | ||
| file.createNewFile(); | ||
| } | ||
| //1024 Is the maximum space that can be created , To avoid not knowing how big the file is | ||
| byte[] in = new byte[1024]; | ||
| // Read the contents of the file | ||
| fis.read(in); | ||
| System.out.prinln(new String(in)); | ||
| ·FileOutputStream Output stream | ||
| String path = "D:/test.txt"; | ||
| File file = new Path(); | ||
| if(!file.exists()){ | ||
| // If not, create a file | ||
| file.createNewFile(); | ||
| } | ||
| FileOutputStream fos = new FileOutputStream(file); | ||
| byte[] out = {'1','2','3'}; | ||
| fos.write(out); | ||
| · If you want to save objects , You can use | ||
| ObjectInputStream And ObjectOutputStream | ||
| · among ,input Indicates input , Read ;output Identify the output , The write ; | ||
| · Operations on objects ObjectInputStream And ObjectOutputStream | ||
| Character stream | ||
| · Character stream operations inherit from abstract classes | ||
| Reader And Writer | ||
| · Generally operate on files , Will use FileReader And FileWriter | ||
| How to improve byte stream efficiency | ||
| ·BufferedInputStream And BufferedOutputStream | ||
| · Because the byte stream is through byte To transmit , and byte The maximum transmission is 1024,1024byte=1kb, The file transferred is very small , So how do we optimize it , | ||
| Then we need to use BufferedInputStream And BufferedOutputStream To transmit ,byte It's similar to that every time we transmit, it's in bytes , It's like a string, | ||
| Then through the String【】 Every time we transmit an array, we transmit it group by group , therefore Buffered That's how it works , We go through Buffered The blessing , We are a group byte A group of byte The transmission of . | ||
| InputStream is = new FileInputStream(sourcePath); | ||
| BufferedInputStream bis = new BufferedInputStream(is); | ||
| OutputStream os = new FileOutputStream(desPath); | ||
| BufferedOutputStream bos = new BufferedOutputStream(os); | ||
| byte[] in = new byte[1024]; | ||
| int count= 0; | ||
| while ((count = bis.read(in)) != -1) { | ||
| bos.write(in, 0, count); | ||
| } | ||
| bis.close(); | ||
| bos.close(); |
版权声明
本文为[Fu Sheng Ruo Meng 521]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220842001974.html
边栏推荐
猜你喜欢

有哪些业务会用到物理服务器?

How can e-procurement become a value-added function in the supply chain?

Easyswool environment configuration

一些使用代理IP的小技巧。

Shardingsphere introduction and sub table usage
![[tutorial] how to use GCC](/img/60/c5804fc4da965afaa3cc72c44a11f9.png)
[tutorial] how to use GCC "zero assembly" for white whoring MDK

012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Leetcode40 - total number of combinations II

What is an API interface?

Longest common subsequence (record path version)
随机推荐
有哪些业务会用到物理服务器?
What business scenarios will the BGP server be used in?
Numerical remapping method (remap)
006_redis_jedis快速入门
2022.4.22-----leetcode. three hundred and ninety-six
JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
002_Redis_String类型常见的操作命令
What are the common proxy IP problems?
keil mdk中文乱码,两种解决方法,字体不再难看
leetcode:27. 移除元素【count remove小操作】
Heap overflow of kernel PWN basic tutorial
拨号vps会遇到什么问题?
How to configure iptables to realize local port forwarding
从开源爱好者到 Apache 董事,一共分几步?
World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
PID精讲
What is a dial-up server and what is its use?
How to choose a good dial-up server?
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
A simple and open source navigation website source code