opslabJutil
opslabJutil copied to clipboard
function countLines in [com.opslab.util.FileUtil] at line 71 may not calc the right lines
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();
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;
}