运用java的io流,进行简单的拷贝图片。

 

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo01 {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

String file1 = "C:/Users/guoyongfeng/Desktop/test/a.png";
String file2 = "C:/Users/guoyongfeng/Desktop/test/b.png";

//创建一个文件的输入流和输出流
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);

//1.先从a.png读数据
int b;
int i = 0;
while( (b = fis.read()) != -1){
i++;
System.out.println(i);
//2.读完数据后,写到b.png
fos.write(b);
}

//3.关闭流
fis.close();
fos.close();

System.out.println("文件拷贝完毕...");


}

}

posted @ 2018-04-24 12:58  sun丶凹凸曼  阅读(546)  评论(0编辑  收藏  举报