package com.pqs9900.util.csv;

import org.mozilla.universalchardet.UniversalDetector;

/**
 * system
 *
 * @author cdf
 * @date 2021/12/14
 */
public class GetByteEncode {
    /**
     * 获取文件编码类型
     *
     * @param bytes 文件bytes数组
     * @return      编码类型
     */
    public static String getEncoding(byte[] bytes) {
        String defaultEncoding = "UTF-8";
        UniversalDetector detector = new UniversalDetector(null);
        detector.handleData(bytes, 0, bytes.length);
        detector.dataEnd();
        String encoding = detector.getDetectedCharset();
        detector.reset();
        if (encoding == null) {
            encoding = defaultEncoding;
        }
        System.out.println(encoding);
        return encoding;
    }

}
