6、[简答题] 【字节流复制文件】 描述:利用字节流将E盘下的a.png图片复制到D盘下(文件名保存一致) 要求: 一次读写一个字节的方式
6、[简答题] 【字节流复制文件】
描述:利用字节流将E盘下的a.png图片复制到D盘下(文件名保存一致)
要求:
一次读写一个字节的方式
package day_09_test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
//6、[简答题] 【字节流复制文件】
//描述:利用字节流将E盘下的a.png图片复制到D盘下(文件名保存一致)
//要求:
//一次读写一个字节的方式
public class Test6 {
public static void main(String[] args) throws IOException {
/* //创建数据源
FileInputStream fileInputStream = new FileInputStream("e:\\a.png");//读数据
FileOutputStream fileOutputStream = new FileOutputStream("d:\\a_copy.png");//写数据
//定义变量,循环次数
int len;
byte[] b = new byte[1024];
//循环读数据
while ((len = fileInputStream.read() )!=-1) {
//写数据
fileOutputStream.write(b,0,len);
}
fileInputStream.close();
fileOutputStream.close();*/
FileInputStream fi = new FileInputStream("E:\\a.png");
FileOutputStream fo = new FileOutputStream("D:\\a_copy.png");
int len;
while ((len= fi.read())!=-1){
fo.write(len);
}
fi.close();
fo.close();
}
}

浙公网安备 33010602011771号