FormFile upfile = update.getUpfile();
String realPath = getServlet().getServletContext().getRealPath("/");
// String realPath = request.getRealPath("");
String filepath = realPath+"/upfile";
String filename = upfile.getFileName();
int filesize = upfile.getFileSize();
File file=new File(filepath,filename);
byte a[] = new byte[filesize];
try {
InputStream in = upfile.getInputStream();
int read=0; //实际读出的文件长度
int allread=0; //共读出的文件长度
while(allread<filesize){
read=in.read(a,allread,filesize);
allread+=read;
}
FileOutputStream out=new FileOutputStream(file);
out.write(a);
in.close();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
posted on 2008-07-29 10:04
Hank1026 阅读(5642)
评论(2) 编辑 收藏 所属分类:
每日积累