当前位置:网站首页>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();
}
}
边栏推荐
猜你喜欢

JMeter test result output

3311. Longest arithmetic

4279. Cartesian tree

Inno Setup 制作安装包

PAT甲级真题1166

JS monitors empty objects and empty references

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

Take you through the whole process and comprehensively understand the software accidents that belong to testing

【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘

Wireshark software usage
随机推荐
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘
Arduino Serial系列函数 有关print read 的总结
Circuit, packet and message exchange
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
SecureCRT password to cancel session recording
Shim and Polyfill in [concept collection]
Inno setup production and installation package
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
Distributed lock
Win 10 find the port and close the port
Laravel Web Framework
[solved] win10 cannot find a solution to the local group policy editor
php artisan
GStreamer ffmpeg avdec decoded data flow analysis
【CMake】CMake链接SQLite库
Win 2008 R2 crashed at the final installation stage
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
3311. 最长算术
[most detailed] latest and complete redis interview book (50)