How To Count Lines From Txt Java

[Solved] How To Count Lines From Txt Java | Scala - Code Explorer | yomemimo.com
Question : get number of lines in a file java

Answered by : abdullah-0kvpuik7ilzv

BufferedReader reader = new BufferedReader(new FileReader("file.txt"));
int lines = 0;
while (reader.readLine() != null) lines++;
reader.close();

Source : https://stackoverflow.com/questions/1277880/how-can-i-get-the-count-of-line-in-a-file-in-an-efficient-way/1277904 | Last Update : Thu, 09 Sep 21

Question : number of lines in file java

Answered by : anders-hansen

// Get lines in a file
public int linesInFile(String path) {	try {	return (int) Files.lines(Paths.get(path)).count(); // Get lines and convert to integer	} catch(IOException e) {	e.printStackTrace(); // Print error if file does not exist.	}	return -1; // Return -1, if file does not exist.
}

Source : | Last Update : Sun, 16 Jan 22

Question : how to count lines from txt java

Answered by :

Path path = Paths.get(fileName);
long lines = 0;
lines = Files.lines(path).count();
System.out.println(lines);

Source : https://mkyong.com/java/how-to-get-the-total-number-of-lines-of-a-file-in-java/ | Last Update : Wed, 02 Mar 22

Answers related to how to count lines from txt java

Code Explorer Popular Question For Scala