使用Apache Tika检测mime类型时,PDF文件上的FileNotFoundException

时间:2016-05-24 10:10:10

标签: java mime-types apache-tika

这是一个像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);
}

如果这不是错误,我该如何解决?

0 个答案:

没有答案