一 字节流的复制
1.1 字节流复制
1.代码
package com.ljf.spring.boot.demo.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @ClassName: FileIo
* @Description: TODO
* @Author: admin
* @Date: 2024/02/18 12:14:37
* @Version: V1.0
**/
public class FileIo {
public static void main(String[] args) {
FileInputStream fileInputStream=null;
FileOutputStream fileOutputStream=null;
try {
fileInputStream=new FileInputStream(new File("d:/liu.txt"));
fileOutputStream=new FileOutputStream(new File("e:/liu.txt"));
byte[] b=new byte[1024];
int len=0;
while((len=fileInputStream.read(b))!=-1){
fileOutputStream.write(b,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fileOutputStream != null){
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
2.文件内容

3.复制后

1.2 字节流write方法
1.代码
FileOutputStream fileOutputStream1= null;
try {
fileOutputStream1 = new FileOutputStream(new File("d:/liu.txt"));
fileOutputStream1.write("abcd".getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
fileOutputStream1.close();
}
2.书写内容


被折叠的 条评论
为什么被折叠?



