如何从epub文件中读取整章?

时间:2011-12-08 09:25:11

标签: android epub

我想制作 epub reader app.Now我只获取文件中的章节名称,但是如何在章节中获取整个数据。

1 个答案:

答案 0 :(得分:2)

我想我之前已经发布了这个。 使用你可以google的nl.siegmann.epublib。 在我的代码中,我将向您展示我如何看待Book类,它显示了epub的工作原理。 在书籍课上使用Spine,我得到书中最大的书脊,这意味着整本书。 然后我将其转换为字符串。

以下是我如何做的代码。

public String getEntireBook()
    {
        String line, linez = null;
        Spine spine = amBook().getSpine();
        Resource res;
        List<SpineReference> spineList = spine.getSpineReferences() ;

        int count = spineList.size();
        int start = 0;

        StringBuilder string = new StringBuilder();
        for (int i = start; count > i; i = i +1) {
            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();}
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
        return linez;
    }