Answers for "how to read only a certian amount of lines in a file java"

2

number of lines in file java

// 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.
}
Posted by: Guest on January-09-2022

Code answers related to "how to read only a certian amount of lines in a file java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language