拷贝图片
package intputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author 王金龙
* @date 创建时间: 2017-2-10 下午2:35:39
* @version 1.0
*/
public class CopyPicture {
public static void main(String[] args) throws IOException {
//找到目标文件
File file = new File("F:\\1.jpg");
//给出输出目录
File file2 = new File("E:\\4.jpg");
ReadPicture(file,file2);
}
public static void ReadPicture(File file,File file2) throws IOException{
//建立读入通道
FileInputStream fileInputStream = new FileInputStream(file);
//建立缓冲数组配合循环读取文件数据
byte[] buf=new byte[1024];
int length = 0;
while((length = fileInputStream.read(buf))!=-1){
//边度边写
WriterPicture(buf,file2);
}
fileInputStream.close();
}
public static void WriterPicture(byte[] buf,File file2) throws IOException{
//建立写的通道
FileOutputStream fileOutputStream = new FileOutputStream(file2,true);
//写入数据
fileOutputStream.write(buf);
//关闭资源
fileOutputStream.close();
}
}