处理代码如下
@At("/doUpload")
@Ok("jsp:file.uploadFile")//缓存位置,文件上限大小,编码,最大文件个数 直接标注稍后使用json解析properties配置
@AdaptBy(type=UploadAdaptor.class,args={"${app.root}/WEB-INF/tmp","8192", "UTF-8", "10" })
public void doUploadFile(@Param("file") TempFile file, HttpServletRequest request,
ServletContext context) {
File f = file.getFile(); // 这个是保存的临时文件
FieldMeta meta = file.getMeta(); // 这个原本的文件信息
String oldName = meta.getFileLocalName(); // 这个时原本的文件名称
System.out.println("=======oldName:"+oldName);
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
FileChannel incChannel = null;
FileChannel outChannel = null;
try {
inputStream = new FileInputStream(f);
File file2 = new File("D:\\cest\\"+oldName);
outputStream = new FileOutputStream(file2);
incChannel = inputStream.getChannel();
outChannel = outputStream.getChannel();
try {
incChannel.transferTo(0, incChannel.size(), outChannel);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
try {
inputStream.close();
outputStream.close();
incChannel.close();
outChannel.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}