Apache Tika 能提取中文、日文等外语吗?
我有以下代码:
Detector detector = new DefaultDetector();
Parser parser = new AutoDetectParser(detector);
InputStream stream = new ByteArrayInputStream(bytes);
OutputStream outputstream = new ByteArrayOutputStream();
ContentHandler textHandler = new BodyContentHandler(outputstream);
Metadata metadata = new Metadata();
// Set<String> langs = LanguageIdentifier.getSupportedLanguages();
// metadata.set(Metadata.CONTENT_LANGUAGE, lang);
// metadata.set(Metadata.FORMAT, hint);
ParseContext context = new ParseContext();
try {
parser.parse(stream, textHandler, metadata, context);
String extractedText = outputstream.toString();
return extractedText;
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (TikaException e) {
e.printStackTrace();
}
如果输入的是包含中文字符的doc文件,每个中文字符将被提取为“?”。
非常感谢!