当前位置:网站首页>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();
}
}
边栏推荐
- Split small interface
- Circuit, packet and message exchange
- 在 4EVERLAND 上存储 WordPress 媒体内容,完成去中心化存储
- MySQL mistakenly deleted the root account and failed to log in
- Wireshark software usage
- 专题 | 同步 异步
- 2021-07-18
- Spa single page application
- 《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
- 1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
猜你喜欢

Selenium key knowledge explanation

PAT甲级真题1166

Circuit, packet and message exchange

带你全流程,全方位的了解属于测试的软件事故

深度学习参数初始化(一)Xavier初始化 含代码

Setting up the development environment of dataworks custom function

How to specify the execution order for multiple global exception handling classes

JUC forkjoinpool branch merge framework - work theft

File operation serialization recursive copy
![[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet](/img/9d/42dfef67246740f0dba0c6d8f1b625.jpg)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
随机推荐
sharepoint 2007 versions
专题 | 同步 异步
Selenium key knowledge explanation
How to specify the execution order for multiple global exception handling classes
Pat grade a real problem 1166
Mise en place d'un environnement de développement de fonctions personnalisées
Pits encountered in the use of El checkbox group
Jeecg menu path display problem
PHP install composer
20220319
High concurrency memory pool
3311. 最长算术
Some experiences of Arduino soft serial port communication
Advanced API (character stream & net for beginners)
Resthighlevelclient gets the mapping of an index
C WinForm framework
File operation serialization recursive copy
4EVERLAND:IPFS 上的 Web3 开发者中心,部署了超过 30,000 个 Dapp!
Shim and Polyfill in [concept collection]
Setting up the development environment of dataworks custom function