Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created September 18, 2021 10:52
Show Gist options
  • Select an option

  • Save GaetanoPiazzolla/cac899d0f80344d7957b39fac86dd768 to your computer and use it in GitHub Desktop.

Select an option

Save GaetanoPiazzolla/cac899d0f80344d7957b39fac86dd768 to your computer and use it in GitHub Desktop.
import java.util.*;
private final static String SEARCH_TOKEN = "searchtoken";
public List<String> searchScanner() {
Path file = Path.of(pathFile);
List<String> found = new ArrayList<>();
final Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
if (lineFromFile.contains(SEARCH_TOKEN)) {
// a match!
found.add(lineFromFile);
}
}
return found;
}
@GaetanoPiazzolla

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment