拷贝图片Java的代码

拷贝图片

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值