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 閱讀(5652)
評論(2) 編輯 收藏 所屬分類:
每日積累