package test.com.atguigu.javase.lesson10;
import org.junit.Test;
import java.io.*;
public class IOTestTest {
@Test
public void testCopyFile() throws IOException {
//1.创建定位到hello.txt的文件的输入流
InputStream inputStream = new FileInputStream("hello.txt");
//2.创建定位到hello2.txt的文件的输出流
OutputStream outputStream = new FileOutputStream("hello2.txt");
//3.创建一个byte数组,用于读写文件
byte[] buffer = new byte[1024 * 10];
int len = 0;
//4.读写文件
while((len = inputStream.read(buffer)) != -1){
outputStream.write(buffer,0,len);
}
//5.关闭流资源
outputStream.close();
inputStream.close();
}
}
文件复制
最新推荐文章于 2025-08-16 09:55:16 发布
601

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



