Answers for "how to search for the occurance of word in text file java"

0

how to find a specific word in a text file in java

String wordToFind="Hello";
List<String> lines=Files.readAllLines(Path.of("yourFile.txt"));
for(int i=0;i<lines.size();i++){
	int col;
    while((col=lines.indexOf(wordToFind))!=-1){
    	System.out.println("found "+wordToFind+" in line "+i+" at column "+col);
    }
}
Posted by: Guest on April-06-2021

Code answers related to "how to search for the occurance of word in text file java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language