当前位置:网站首页>Introduction of buffer flow
Introduction of buffer flow
2022-07-03 07:21:00 【four thousand three hundred and forty-three】

package BufferStream;
/*
The use of buffer streams
*/
import org.junit.Test;
import java.io.*;
public class BufferTest {
/*
Realize the copy of non text file
*/
@Test
public void BufferedStreamTest() throws IOException {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
// 1. Document making object
File srcFile = new File("hanyang.png");
File destFile = new File("hangyang2.png");
// 2. Create byte stream
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(destFile);
// 2.2 Create a buffer stream
bis = new BufferedInputStream(fis);
bos = new BufferedOutputStream(fos);
// 3. Data manipulation
byte[] buffer = new byte[5];
int len ;
while ((len = bis.read(buffer))!=-1){
bos.write(buffer,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bos!=null) {
bos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (bis!=null) {
bis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// 4. Resources to shut down : Close the outer layer first , Then close the inner layer . notes : While closing the outer layer , The inner flow will also be automatically closed
// fos.close();
// fis.close();
}
}
边栏推荐
- File links cannot be opened or downloaded in Google browser
- Distributed transactions
- [most detailed] latest and complete redis interview book (50)
- 树莓派更新工具链
- Store WordPress media content on 4everland to complete decentralized storage
- 4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
- Jeecg request URL signature
- docker建立mysql:5.7版本指定路径挂载不上。
- The difference between typescript let and VaR
- dataworks自定义函数开发环境搭建
猜你喜欢

Wireshark software usage

Final, override, polymorphism, abstraction, interface

Win 10 find the port and close the port

Pat grade a real problem 1166

《指环王:力量之戒》新剧照 力量之戒铸造者亮相

Map interface and method

Flask Foundation

Inno Setup 制作安装包

Interfaces and related concepts

How to specify the execution order for multiple global exception handling classes
随机推荐
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
Basic knowledge about SQL database
dataworks自定義函數開發環境搭建
dataworks自定义函数开发环境搭建
带你全流程,全方位的了解属于测试的软件事故
3311. 最长算术
Summary of Arduino serial functions related to print read
Longest common prefix and
【最详细】最新最全Redis面试大全(50道)
Advanced API (use of file class)
Flask Foundation
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘
Use of framework
Advanced API (byte stream & buffer stream)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
The underlying mechanism of advertising on websites
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
Basic components and intermediate components
LeetCode