当前位置:网站首页>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
边栏推荐
猜你喜欢
如何“优雅”的测量系统性能
NPM yarn startup error [resolved]
How to classify proxy IP?
【汇编语言】从最底层的角度理解“堆栈”
What are the test steps of dynamic proxy IP?
简洁开源的一款导航网站源码
ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
LeetCode 447. Number of boomerangs (permutation and combination problem)
How to initialize "naming and surname" in C language
Realize linear regression with tensorflow (including problems and solutions in the process)
随机推荐
Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
Shardingsphere read write separation
浅析静态代理ip的三大作用。
Makefile文件是什么?
校园转转二手市场源码
What is a proxy IP pool and how to build it?
leetcode:27. Remove element [count remove]
Leetcode46 Full Permutation
A simple and open source navigation website source code
Shardingsphere sub database and sub table
[experience tutorial] Alipay balance automatically transferred to the balance of treasure how to set off, cancel Alipay balance automatically transferred to balance treasure?
中金财富跟中金公司是一家公司吗,安全吗
006_redis_jedis快速入门
MySQL active / standby configuration binary log problem
如何选择一台好的拨号服务器?
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
一些使用代理IP的小技巧。
Challenges often faced by client project management
搭建个人主页保姆级教程(二)
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face