`
laozhou
  • 浏览: 36606 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

图片写入文件夹

阅读更多
private static void copy(File src, File dst) {
	try {
	    InputStream in = null;
	    OutputStream out = null;
	    try {
		in = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE);
		out = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE);
		byte[] buffer = new byte[BUFFER_SIZE];
		while (in.read(buffer) > 0) {
		    out.write(buffer);
		}
	    } finally {
		if (null != in) {
		    in.close();
		}
		if (null != out) {
		    out.close();
		}
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }


调用:

if (myFile != null && myFile.size() > 0) {

    File imageFile1 = new File(ServletActionContext.getServletContext().getRealPath("images") + "/" + "t01.jpg");
  
   
    if (myFile.get(0) != null) {
copy(myFile.get(0), imageFile1);
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics