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

Solutions on MaxInterview for how to find a specific word in a text file in java by the best coders in the world

showing results for - "how to find a specific word in a text file in java"
Lorena
17 Jan 2016
1String wordToFind="Hello";
2List<String> lines=Files.readAllLines(Path.of("yourFile.txt"));
3for(int i=0;i<lines.size();i++){
4	int col;
5    while((col=lines.indexOf(wordToFind))!=-1){
6    	System.out.println("found "+wordToFind+" in line "+i+" at column "+col);
7    }
8}