yangys
2025-06-27 26f07223e1b33a8eb5ee184041575e9b204cfebe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.springblade.mdm.utils;
 
import org.apache.tika.Tika;
 
import java.io.IOException;
import java.io.InputStream;
 
public class FileContentUtil {
 
    /**
     * 判断是否文本类型
     * @param inputStream
     * @return
     */
    public static boolean isTextFile(InputStream inputStream) {
        Tika tika = new Tika();
        try {
            String mimeType = tika.detect(inputStream);
            //String mimeType = tika.detect(file);
            return mimeType.startsWith("text/")
                || mimeType.equals("application/xml")
                || mimeType.equals("application/json");
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}