标签:ipa 代码 nbsp filename head 最大 parse write zemax
文件上传
##前台:
form表单submit提交,form增加样式 enctype="multipart/form-data" method="post";
##后台
//String path为服务器保存文件的路径
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(5*1024);//缓存
factory.setRespository(new File(tempPath));//临时文件路径
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
upload.setSizeMax(8888*1024*1024);//设置最大
List<FileItem> items = upload.parseRequest(request);
FileItem item = items.get(i);
if(!item.isFormField()){
fileName = item.getName();
String[] str = fileName.split("\\.");
String fileType = str[str.lenth-1];
InputStream in = item.getInputStream();//读取数据写入文件
FileOutputStream out = new FileOutputStream(path);
byte buffer[] = new byte[1024];
int len = 0;
while((len=in.read(buffer))>0){
out.write(buffer,0len);
}
item.delete();
}
标签:ipa 代码 nbsp filename head 最大 parse write zemax
原文地址:http://www.cnblogs.com/exayong/p/7226329.html