Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

获取文件指针这个方法countSeek你是不是忘记加break了 #17

Closed
yunis-du opened this issue Jan 9, 2020 · 0 comments
Closed

Comments

@yunis-du
Copy link

yunis-du commented Jan 9, 2020

String str = ""; while ((str = ra.readLine()) != null) { line++; if (line == currentLine) { this.seek = ra.getFilePointer(); } }
你这样写的话就算跳到第十页都要循环完全部文件而且加上break的话我要跳到十万行也是很慢的。
我对你的代码稍稍修改了一下
`private void initBook() {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(new File(bookFile));
bookList = IOUtils.readLines(fileInputStream, "UTF-8");
this.totalLine = bookList.size();
} catch (IOException e) {
e.printStackTrace();
}
}

private String turnPage() {
    if (!this.bookList.isEmpty()) {
        currentLine++;
        return bookList.get(currentLine - 1);
    }
    return "";
}`

加到list的话对于行数大的小说来说跳页要快很多很多,亲测

@yisier yisier closed this as completed Sep 27, 2020
@yisier yisier reopened this Sep 27, 2020
@yisier yisier closed this as completed Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants