这是控制器里的 @RequestMapping(value = "/inputfile", method = RequestMethod.POST)
public ModelAndView addFile(HttpServletRequest request) {
String filepath = request.getSession().getServletContext()
.getRealPath("/");// 获取项目部署在服务器上的根路径
// 将MultipartHttpServletRequest转换为HttpServletRequest对象
MultipartHttpServletRequest muRequest = (MultipartHttpServletRequest) request;
File file = null;
Iterator<String> filenames = muRequest.getFileNames();// 获取文件名
MultipartFile multipartFile = muRequest.getFile(filenames.next());
// 获取源文件名
String name = multipartFile.getOriginalFilename();
// 文件保存路径
String filePath = filepath + "/uploadfile/input/" + name;
try {
saveFile(filePath, multipartFile.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}public void saveFile(String filePath, byte[] content) throws IOException { //保存上传文件的方法 
BufferedOutputStream bos = null;
try {
File file = new File(filePath);
// 判断文件路径是否存在
if (!file.getParentFile().exists()) {
// 文件路径不存在时,创建保存文件所需要的路径
file.getParentFile().mkdirs();
}
// 创建文件(这是个空文件,用来写入上传过来的文件的内容)
file.createNewFile();
bos = new BufferedOutputStream(new FileOutputStream(file));
bos.write(content);
} catch (FileNotFoundException e) {
throw new FileNotFoundException("文件不存在。" + e);
} finally {
if (null != bos) {
bos.close();
}
}
}你可以看看这个。。不知道对你有没帮助