Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

get number of lines in a file java

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

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.
}
Comment

PREVIOUS NEXT
Code Example
Java :: java ip regex pattern 
Java :: register command spigot 
Java :: print files in java 
Java :: how to parse double upto 2 decimal in java 
Java :: foreground java jframe 
Java :: take a value from keyboard java 
Java :: How do you print duplicate characters from a string? 
Java :: finding absolute value in java 
Java :: javafx listview get item index 
Java :: maven spring-boot-configuration-processor install 
Java :: java bubble sort 
Java :: ova definition 
Java :: stream to list 
Java :: java file reader utf 8 
Java :: how to remove character from stringbuilder in java 
Java :: StringBuilder java pop back 
Java :: A horizontal line must be drawn through the diamond, centered vertically. • The message must be printed just above the line. • The message must be horizontally centered within the applet 
Java :: android hide textview 
Java :: What AJAJ stand for 
Java :: make recycler view non scrollable 
Java :: how to convert int to string java 
Java :: scan.nextline not waiting for input 
Java :: list to lowercase java 
Java :: rdd. map with condition 
Java :: java swing absolute position 
Java :: remove action bar android studio 
Java :: map java get first key 
Java :: java button actionlistener 
Java :: java switch class instanceof 
Java :: java ee check if session exists or is new 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =