package IO;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.Test;
//完成字符流和字节流的输入输出
public class TestExer {
// 字符流利用程序复制
@Test
public void test4() {
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
bufferedReader = new BufferedReader(new FileReader("test1.txt"));
bufferedWriter = new BufferedWriter(new FileWriter("hadi.txt"));
char[] c = new char[20];
int len;
while ((len = bufferedReader.read(c)) != -1) {
bufferedWriter.write(c, 0, len);
}
bufferedWriter.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (bufferedWriter != null
IOの利用字节流和字符流完成文件的复制demo
最新推荐文章于 2021-08-22 22:58:56 发布
该Java代码示例展示了如何利用BufferedReader和BufferedWriter进行字符流复制,以及如何使用BufferedOutputStream进行字节流复制。通过FileReader, FileWriter, FileOutputStream和FileInputStream,实现了文件内容的读取和写入,同时展示了如何处理IOException。"
132292078,19694862,连续学习在图像相机定位中的应用,"['深度学习', '计算机视觉', '图像处理', '相机定位', '机器学习']
摘要由CSDN通过智能技术生成