【发布时间】:2015-07-20 08:49:34
【问题描述】:
我有一个文档文件,其中多个段落也有一些标题。我想要代码的 ArrayList 中的标题和段落。我无法找到我的解决方案。请提出合适的解决方案。
提前致谢。
【问题讨论】:
我有一个文档文件,其中多个段落也有一些标题。我想要代码的 ArrayList 中的标题和段落。我无法找到我的解决方案。请提出合适的解决方案。
提前致谢。
【问题讨论】:
这是读取 doc 文件并获取文本的代码。 阅读后,这一切都取决于您要对文本做什么。
String extPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.Separator;
AssetManager assetManager= getApplicationContext().getAssets();
InputStream inputStream = assetManager.open(extPath + "file.doc");
String text = loadFile(inputStream);
loadFile方法是---
public String loadFile(InputStream inputStream){
ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] bytes = new byte[4096];
int length = 0;
while(){
b.write(bytes, 0, length);
}
return new String(b.toByteArray(), "UTF8");
}
【讨论】: