拷贝图片Java的代码

来源:互联网 发布:数据库是什么 编辑:程序博客网 时间:2024/05/16 10:54

拷贝图片

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();}}


0 0
原创粉丝点击