11.17
今天练习的是缓冲技术的代码:
代码部分;
package lianxi;
import java.io.*;
public class bo
{
public static void main(String[] args) {
try {
byte[] data = new byte[1];
File srcFile = new File("D://c.txt");
File desFile = new File("D://d.txt");
BufferedInputStream bufferedInputStream =
new BufferedInputStream(
new FileInputStream(srcFile));
BufferedOutputStream bufferedOutputStream =
new BufferedOutputStream(
new FileOutputStream(desFile));
System.out.println("复制文件:" +
srcFile.length() + "字节");
while(bufferedInputStream.read(data) != -1) {
bufferedOutputStream.write(data);
}
// 将缓冲区中的数据全部写出
bufferedOutputStream.flush();
// 关闭流
bufferedInputStream.close();
bufferedOutputStream.close();
System.out.println("复制完成");
}
catch(IOException e) {
e.printStackTrace();
}
}
}
运行结果:
运行结果分析:
最后成功吧C文件里的内容复制到D文件。