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

function countLines in [com.opslab.util.FileUtil] at line 71 may not calc the right lines #7

Open
riclava opened this issue Sep 6, 2016 · 1 comment

Comments

@riclava
Copy link

riclava commented Sep 6, 2016

these code works

InputStream input = new FileInputStream(file);
BufferedReader b = new BufferedReader(new InputStreamReader(input));
String value = b.readLine();
if (value != null)
    while (value != null) {
        count++;
        value = b.readLine();
    }
b.close();
input.close();
@0opslab
Copy link
Owner

0opslab commented Sep 7, 2016

thanks! it's not the best way!
maybe!

public final static int countLines(File file) {
        try(LineNumberReader rf = new LineNumberReader(new FileReader(file))){
            long fileLength = file.length();
            rf.skip(fileLength);
            return rf.getLineNumber();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }

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