src/main/java/com/rockagen/commons/util/XmlUtil.java
public static String getEncoding(String xmlStr) {
        String result;

        String xml = xmlStr.trim();

        if (xml.startsWith("<?xml")) {
            int end = xml.indexOf("?>");
            int encIndex = xml.indexOf("encoding=");
            if (encIndex != -1) {
                String sub = xml.substring(encIndex + 9, end);
                result = CommUtil.substringBetween(sub, "\"", "\"");
                return result;
            }
        }
        return null;
    }
public static String getEncoding(String xmlStr) {
        String result;

        String xml = xmlStr.trim();

        if (xml.startsWith("<?xml")) {
            int end = xml.indexOf("?>");
            int encIndex = xml.indexOf("encoding=");
            if (encIndex != -1) {
                String sub = xml.substring(encIndex + 9, end);
                result = CommUtil.substringBetween(sub, "\"", "\"");
                return result;
            }
        }
        return null;
    }
public static String getEncoding ( String xmlStr ) { String result ; String xml = xmlStr . trim ( ) ; if ( xml . startsWith ( "<?xml" ) ) { int end = xml . indexOf ( "?>" ) ; int encIndex = xml . indexOf ( "encoding=" ) ; if ( encIndex != - 1 ) { String sub = xml . substring ( encIndex + 9 , end ) ; result = CommUtil . substringBetween ( sub , "\"" , "\"" ) ; return result ; } } return null ; }
Obtain xml file encoding attribute

@param xmlStr xml String
@return encoding value
Obtain xml file encoding attribute