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 :: get tfidf score for a sentence 
Java :: string to int java 
Java :: spring boot id auto generated 
Java :: array to map java3 
Java :: max long 
Java :: java remove non numbers from string 
Java :: java android play sound file with variable 
Java :: convert java date to sql date 
Java :: java ip regex pattern 
Java :: how to parse double upto 2 decimal in java 
Java :: read int from keyboard java 
Java :: how to convert object to list in java 
Java :: javafx listview get item index 
Java :: HTTP FAILED: java.net.UnknownServiceException: CLEARTEXT communication to ztdev.co.za not permitted by network security policy 
Java :: take string array input in java 
Java :: update value in hashmap java 
Java :: java stream collect to string 
Java :: duck number in java 
Java :: read file using scanner in java 
Java :: new int [] in java with assigned values 
Java :: change date jdatepicker java 
Java :: W/System.err: java.io.IOException: Cleartext HTTP traffic to not permitted 
Java :: How to execute Shell Commands with Java and print the output directly while executing the command 
Java :: scan.nextline not waiting for input 
Java :: scanner in java 
Java :: character classes in regex 
Java :: how to build a java main menu 
Java :: toast.maketext error kotlin 
Java :: how to compare 3 numbers in java 
Java :: check if table exist sqlite java 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =