Merge pull request #7384 from alvasw/file_keywork_scanner_close_file_descriptors

FileUtils: Close files after scanning for keywords
This commit is contained in:
Alejandro García 2025-02-06 21:46:37 +00:00 committed by GitHub
commit 16a0f45d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -263,10 +263,11 @@ public class FileUtil {
} }
public static boolean doesFileContainKeyword(File file, String keyword) throws FileNotFoundException { public static boolean doesFileContainKeyword(File file, String keyword) throws FileNotFoundException {
Scanner s = new Scanner(file); try (Scanner s = new Scanner(file)) {
while (s.hasNextLine()) { while (s.hasNextLine()) {
if (s.nextLine().contains(keyword)) { if (s.nextLine().contains(keyword)) {
return true; return true;
}
} }
} }
return false; return false;