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

FileReader And FileWriter Can only be used for text files , Such as .txt,.java,.c,.c++ etc.
For the picture , Byte stream files such as video need byte stream, i.e :FileInputStream And FileOutputStream
package IOStream;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class InputOutputStream {
@Test
public void test() throws IOException {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
File srcFile = new File("hanyang.png");
File destFile = new File("hanyang1.png");
fis = new FileInputStream(srcFile);
fos = new FileOutputStream("hanyang1.png");
byte[] buffer = new byte[5];
int len ;
while((len = fis.read(buffer))!= -1){
fos.write(buffer,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
边栏推荐
- CentOS php7.3 installing redis extensions
- [day15] introduce the features, advantages and disadvantages of promise, and how to implement it internally. Implement promise by hand
- Sorting, dichotomy
- Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
- 【最详细】最新最全Redis面试大全(50道)
- Dora (discover offer request recognition) process of obtaining IP address
- TypeScript let与var的区别
- Summary of abnormal mechanism of interview
- Win 10 find the port and close the port
- 691. 立方体IV
猜你喜欢

Win 10 find the port and close the port
![[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones](/img/d0/850e095a43610366d6144b2471f3f7.jpg)
[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

在 4EVERLAND 上存储 WordPress 媒体内容,完成去中心化存储

Arduino Serial系列函数 有关print read 的总结

Summary of abnormal mechanism of interview

Summary of Arduino serial functions related to print read

Interview questions about producers and consumers (important)

专题 | 同步 异步

【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘
随机推荐
Topic | synchronous asynchronous
dataworks自定義函數開發環境搭建
Summary of abnormal mechanism of interview
Realize the reuse of components with different routing parameters and monitor the changes of routing parameters
Common analysis with criteria method
docket
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
Jeecg menu path display problem
php artisan
"Moss ma not found" solution
Circuit, packet and message exchange
TypeScript let与var的区别
691. Cube IV
SharePoint modification usage analysis report is more than 30 days
[most detailed] latest and complete redis interview book (50)
萬卷書 - 價值投資者指南 [The Education of a Value Investor]
[untitled]
专题 | 同步 异步
CentOS php7.3 installing redis extensions
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong