【复制图片】

这次这个是复制图片到规定路径,其实就是读出来选定的图片,然后在规定的路径下写入。

上代码:

private void saveImage(String path,String savePath) throws Exception {

// path是源图片的路径 完整的 如: c:/temp/123.jpg

//savePath是目标路径 完整的 如: d:/temp/456.jpg

File file = new File (savePath.substring(0,savePath.lenth()-11));

//这里的savePath.substring(0,savePath.lenth()-11是需要用的时候改动的,因为这里是创建目录的,不要 图片名字
if(null != file && !file.isDirectory()){
file.mkdirs();
}

//写入图片

BufferedInputStream ips = new BufferedInputStream(new URL(path).openStream());
File saveFile = new File(savePath);
BufferedOutputStream ops = new BufferedOutputStream(new FileOutputStream(saveFile));
byte[] buf = new byte[1024];
int i =0;
boolean isFirst = true;
try{
while((i=ips.read(buf)) != -1){
ops.write(buf,0,i);

}
}catch(Exception e){
throw e;
}finally{
ops.flush();
if(ips != null)ips.close();
if(ops != null) ops.close();
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值