Apache tika detects mime-type incorrectly for csv

后端 未结 1 1634
失恋的感觉
失恋的感觉 2021-01-14 09:29

I\'ve created .csv file using excel and I wrote following code using apache tika:

public static boolean checkThatMimeTypeIsCsv(InputStream input         


        
相关标签:
1条回答
  • 2021-01-14 10:04

    Try this...

    public static String checkThatMimeTypeIsCsv(String fileName ) throws Exception {
        File sourceFile = new File(fileName );
        DefaultDetector file_detector = new DefaultDetector();
        TikaInputStream file_stream = TikaInputStream.get(sourceFile);
        Metadata metadata = new Metadata();
        metadata.set(Metadata.RESOURCE_NAME_KEY, sourceFile.getName());
        MediaType mediaType = file_detector.detect(file_stream, metadata);              
        String file_type = mediaType.toString();
        System.out.println(file_type);
        return file_type;
    }
    
    0 讨论(0)
提交回复
热议问题