当前位置:网站首页>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();
}
}
}
}
边栏推荐
- The difference between typescript let and VaR
- 《指环王:力量之戒》新剧照 力量之戒铸造者亮相
- Sorting, dichotomy
- PHP install composer
- MySQL syntax (basic)
- JMeter JSON extractor extracts two parameters at the same time
- Pits encountered in the use of El checkbox group
- "Baidu Cup" CTF game 2017 February, Web: blast-1
- 691. Cube IV
- Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
猜你喜欢

Summary of Arduino serial functions related to print read

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

Mise en place d'un environnement de développement de fonctions personnalisées

高并发内存池

JMeter JSON extractor extracts two parameters at the same time

POI excel percentage

JUC forkjoinpool branch merge framework - work theft

3311. 最长算术

Topic | synchronous asynchronous

Recursion, Fibonacci sequence
随机推荐
Win 10 find the port and close the port
Crontab scheduled task
CentOS php7.3 installing redis extensions
PAT甲级真题1166
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
Specified interval inversion in the linked list
JMeter JSON extractor extracts two parameters at the same time
Sorting, dichotomy
Common analysis with criteria method
C WinForm framework
【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘
The underlying mechanism of advertising on websites
Inno setup production and installation package
VMware virtual machine installation
Laravel Web Framework
Book recommendation~
SecureCRT取消Session记录的密码
萬卷書 - 價值投資者指南 [The Education of a Value Investor]
SharePoint modification usage analysis report is more than 30 days
10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]