回覆列表
  • 1 # 使用者1554029809374

    可以透過以下方法來進行編碼格式判斷,輸入一個字串,之後返回字串編碼型別。public static String getEncoding(String str) { String encode = "GB2312"; try { if (str.equals(new String(str.getBytes(encode), encode))) { //判斷是不是GB2312 String s = encode; return s; //是的話,返回逗GB2312逗,以下程式碼同理 } } catch (Exception exception) { } encode = "ISO-8859-1"; try { if (str.equals(new String(str.getBytes(encode), encode))) { //判斷是不是ISO-8859-1 String s1 = encode; return s1; } } catch (Exception exception1) { } encode = "UTF-8"; try { if (str.equals(new String(str.getBytes(encode), encode))) { //判斷是不是UTF-8 String s2 = encode; return s2; } } catch (Exception exception2) { } encode = "GBK"; try { if (str.equals(new String(str.getBytes(encode), encode))) { //判斷是不是GBK String s3 = encode; return s3; } } catch (Exception exception3) { } return ""; //如果都不是,說明輸入的內容不屬於常見的編碼格式。 }

  • 中秋節和大豐收的關聯?
  • 平車縫紉機旋梭的速度怎麼調?