这是一个像Files.probeContentType()
?
我一直在尝试上传 .pdf 文件,但会显示FileNotFoundException
。
我在Ubuntu 14.04 LTS上运行,Files.probeContentType()
和Tika.detect()
无法检测到 .pdf 文件。
if (ServletFileUpload.isMultipartContent(request)) {
DiskFileItemFactory diskFactory = new DiskFileItemFactory();
ServletFileUpload uploadHandler = new ServletFileUpload(diskFactory);
try {
List<FileItem> fileList = uploadHandler.parseRequest(request);
for (FileItem file : fileList) {
if (!file.isFormField()) {
String name = new File(file.getName()).getName();
File image = new File(request.getServletContext().getInitParameter("UploadPath") + File.separator + name);
Tika tika = new Tika();
String mimeType = tika.detect(image);
System.out.println(mimeType);
}
如果这不是错误,我该如何解决?