How To Find The Line Number In A File Based

[Solved] How To Find The Line Number In A File Based | 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

Answers related to how to find the line number in a file based on a condition in java

Code Explorer Popular Question For Scala