2

我正在开发一个应用程序,我想使用 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;
}
4

1 回答 1

0

您可以使用EpubParser逐页分隔 epub 文件。即使它仍然存在一些问题,它也能完成它的工作。

于 2016-04-21T13:55:32.333 回答