使用定义字节数组的方式将D盘中的程序拷贝到E盘中,是io流的常规操作,也是我们必须掌握的知识点
import java.io.*;
public class Demo_06 {
public static void main(String[] args) throws IOException {
// 创建字节输入流对象
InputStream in = new FileInputStream("D:\\navcat\\navicat\\navicatformysql\\Navicat for MySQL\\navicat.exe");
//创建字节输出流对象
OutputStream out = new FileOutputStream("D:/temp/sql2.exe");
int len;
//定义byte(字节)数组,作为缓冲区。(使用缓冲区读写文件可以有效提高程序的效率)
byte[] buff = new byte[1024];
while((len = in.read(buff)) != -1) {
//将读取到的数据写入对应的文件中(输入流中的文件路径)
out.write(buff,0,len);
}
}
}