`

struts2实现文件上传代码方法

阅读更多
/**
* 获得图片  路径至  images
* */
public String getImages(File file,String tu) throws Exception {
System.out.println("pictureFileName:"+file.getName()+"tu:"+tu);
File saved = new File(ServletActionContext.getServletContext().getRealPath("images"),imgsmallFileName);
InputStream ins=null;
OutputStream ous=null;
try {
saved.getParentFile().mkdirs();
ins=new FileInputStream(file);
ous=new FileOutputStream(saved);
byte[] b=new byte[1024];
int len=0;
while((len=ins.read(b))!=-1){
ous.write(b, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(ous!=null){
ous.close();
}
if (ins!=null) {
ins.close();
}
}
return imgsmallFileName;


}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics