opslabJutil icon indicating copy to clipboard operation
opslabJutil copied to clipboard

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

Open riclava opened this issue 9 years ago • 1 comments

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();

riclava avatar Sep 06 '16 12:09 riclava

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;
    }

0opslab avatar Sep 07 '16 14:09 0opslab