当前位置:网站首页>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
边栏推荐
- What categories do you need to know before using proxy IP?
- Echo "new password" |passwd -- stdin user name
- What should I pay attention to when using proxy IP?
- How to set computer IP?
- 什么是api接口?
- Halo open source project learning (I): project launch
- 不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
- Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
- Cc2541 emulator CC debugger tutorial
- 搭建网站是用物理机还是云主机好?
猜你喜欢

【汇编语言】从最底层的角度理解“堆栈”

【动手学深度学习V2】循环神经网络-1.序列模型

How to change the size of SVG pictures without width in openlayer

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

013_基于Session实现短信验证码登录流程分析

PHP & laravel & master several ways of generating token by API and some precautions (PIT)

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

Redis memory recycling strategy

批处理多个文件合成一个HEX

Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
随机推荐
2022.4.20-----leetcode.388
Introduction to esp32 Bluetooth controller API
Today will finally write system out. Println()
简洁开源的一款导航网站源码
Heap overflow of kernel PWN basic tutorial
[tutorial] how to use GCC "zero assembly" for white whoring MDK
在使用代理IP前需要了解哪些分类?
Find the largest number of two-dimensional arrays
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
What is a proxy IP pool and how to build it?
中金财富是国企吗,开户安全吗
How to classify proxy IP?
搭建个人主页保姆级教程(二)
001_redis设置存活时间
009_Redis_RedisTemplate入门
EBS:PO_ EMPLOYEE_ HIERARCHIES_ ALL
Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
postman里面使用 xdebug 断点调试
Realize linear regression with tensorflow (including problems and solutions in the process)
How to "gracefully" measure system performance