トップ 一覧 ping 検索 ヘルプ RSS ログイン

Java 文字コード判定の変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!Java 文字コード判定
[Java]{{cateogyr 文字化け}}
[Java]{{cateogry 文字化け}}

*http://code.google.com/p/juniversalchardet/source/browse/trunk/src/org/mozilla/universalchardet/prober/Big5Prober.java

 public static String detectEncoding(String text) {
     String encoding = null;
 
     try {
         UniversalDetector detector = new UniversalDetector(null);
 
         InputStream is = new StringInputStream(text);
         
         byte[] buf = new byte[1024];
         int nread;
         while ((nread = is.read(buf)) > 0 && !detector.isDone()) {
             detector.handleData(buf, 0, nread);
         }
         detector.dataEnd();
         encoding = detector.getDetectedCharset();
         
         detector.reset();
         
     } catch(Exception e) {
         e.printStackTrace();
     }
     
     return encoding;
 }