Created
September 18, 2021 10:52
-
-
Save GaetanoPiazzolla/cac899d0f80344d7957b39fac86dd768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related to medium article https://gae-piaz.medium.com/search-string-in-file-with-java-as-fast-as-possible-fedafdc7a3ee