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

最佳答案

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

08-27 06:11