「Java 文字コード判定」の版間の差分
ナビゲーションに移動
検索に移動
| (同じ利用者による、間の1版が非表示) | |||
| 1行目: | 1行目: | ||
| − | ==Java 文字コード判定== | + | ==[[Java 文字コード判定]]== |
| − | [[Java]]{{cateogry 文字化け}} | + | [[Java]] | {{cateogry 文字化け}} |
*http://code.google.com/p/juniversalchardet/source/browse/trunk/src/org/mozilla/universalchardet/prober/Big5Prober.java | *http://code.google.com/p/juniversalchardet/source/browse/trunk/src/org/mozilla/universalchardet/prober/Big5Prober.java | ||
2020年2月16日 (日) 04:27時点における最新版
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;
}
© 2006 矢木浩人