Ok, I think I get your issue now.
You can call your method from the main:
public static void main(String[] args) {
//may need to throw file not found exception here
findAndPrint();
}
Then you need to remove the arguments from your method:
public static void findAndPrint() throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("C:\\yourfilepath\\actualfile.txt"));
//you can get user input etc here if necessary
String input = "pass";
while (in.hasNext()) {
String line = in.nextLine();
if (line.contains(input)) {
System.out.println(line);
}
}
}
2
solved method to find and search files JAVA [closed]