当前位置:网站首页>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
边栏推荐
- 2022.4.20-----leetcode. three hundred and eighty-eight
- 002_Redis_String类型常见的操作命令
- 005_redis_set集合
- PID refinement
- J-link v9 使用技巧之虚拟串口功能
- Use Xdebug breakpoint debugging in postman
- 89 logistic regression user portrait user response prediction
- 中金财富是国企吗,开户安全吗
- 世界读书日 | 技术人不要错过的好书(IT前沿技术)
- 013_基于Session实现短信验证码登录流程分析
猜你喜欢

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

我国科学家揭示突破水稻产量瓶颈新机制

Shardingsphere introduction and sub table usage

Leetcode46 Full Permutation

89 logistic regression user portrait user response prediction

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio

MySQL basic record

拨号vps会遇到什么问题?

006_redis_SortedSet类型

校园转转二手市场源码
随机推荐
MySQL active / standby configuration binary log problem
Network jitter tool clumsy
2022.4.10-----leetcode.804
假如404页面是这样的 | 每日趣闻
什么是代理IP池,如何构建?
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
Unity editor hierarchy drop-down menu extension
Why is one plus one equal to two
ESP32蓝牙Bluetooth Controller API介绍
Leetcode46 Full Permutation
What businesses use physical servers?
拨号vps会遇到什么问题?
代理IP可用率是不是等同于代理IP的效率?
leetcode:27. 移除元素【count remove小操作】
Halo open source project learning (I): project launch
J-Link RTT使用
Use of j-link RTT
从开源爱好者到 Apache 董事,一共分几步?
浅析静态代理ip的三大作用。
【dpdk】10. Dpdk DNS learning notes