我正在开发一个应用程序,我希望使用epublib逐页阅读epub文件并在应用程序中显示,我能够明智地获取书籍的所有内容,现在我想获取内容页面明智的,如果你有任何想法,请回答,提前谢谢
这里是用于获取书籍章节内容的代码
public String getText(String filepath) {
String linez = "";
File f = new File(filepath);
InputStream epubInputStream = null;
try {
epubInputStream = new FileInputStream(f);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
Book book = null;
try {
book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Spine spine = book.getSpine();
List<SpineReference> spineList = spine.getSpineReferences();
int count = spineList.size();
txtpages.setText("Size:" + Integer.toString(count) + "\n");
StringBuilder string = new StringBuilder();
for (int i = 0; count > i; i++) {
Resource res = spine.getResource(i);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
try {
while ((line = reader.readLine()) != null) {
linez = string.append(line + "\n").toString();
}
} catch (IOException e) {
e.printStackTrace();
}
// do something with stream
} catch (IOException e) {
e.printStackTrace();
}
}
//webView.loadData(linez, "text/html", "utf-8");
return linez;
}