Get Number Of Lines In A File Java

[Solved] Get Number Of Lines In A File Java | Scala - Code Explorer | yomemimo.com
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

Answers related to get number of lines in a file java

Code Explorer Popular Question For Scala