`
qdexception
  • 浏览: 44320 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

图片写入

阅读更多
Code:

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImgWriteUtil {
private BufferedInputStream bis;
private BufferedOutputStream bos;
public void writeImg(File fromfile, File tofile) {//写入图片
  int len = 0;
  int size = 0;
  try {
   bis = new BufferedInputStream(new FileInputStream(fromfile));
   bos = new BufferedOutputStream(new FileOutputStream(tofile));
   size = (int) fromfile.length();
   byte[] buffer = new byte[size];
   while ((len = bis.read(buffer)) >0) {
    bos.write(buffer, 0, len);
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
   throw new RuntimeException();//抛出unchecked异常,
  } catch (IOException e) {
   e.printStackTrace();
   throw new RuntimeException();//抛出unchecked异常,;
  } finally {
   try {
    if (bos != null) {
     bos.close();
    }
    if (bis != null) {
     bis.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException();//抛出unchecked异常,
   }
  }
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics