public static String getHtmlEncoding(InputStream ins){
int n;
byte[] buf = new byte[4096];
ManHtmlCharsetDetector detector = new ManHtmlCharsetDetector(null);
try{
while ((n=ins.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, n);
}
detector.dataEnd();
}catch(Exception e){
throw new MnsearchException(e);
}
return detector.getDetectedCharset();
}
int n;
byte[] buf = new byte[4096];
ManHtmlCharsetDetector detector = new ManHtmlCharsetDetector(null);
try{
while ((n=ins.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, n);
}
detector.dataEnd();
}catch(Exception e){
throw new MnsearchException(e);
}
return detector.getDetectedCharset();
}
本文介绍了一种通过InputStream读取内容并使用ManHtmlCharsetDetector类来检测HTML文档编码的方法。此方法能够有效地解析输入流并返回检测到的字符集。

1万+

被折叠的 条评论
为什么被折叠?



