About 3,230,000 results
Open links in new tab
  1. java - Search a file for a String and return that String if found ...

    Mar 22, 2013 · How can you search through a txt file for a String that the user inputs and then return that String to the console. I've written some code that doesn't work below, but I hope it can illustrate my p...

  2. Find a string (or a line) in a txt File Java - Stack Overflow

    use String.contains(your search String) instead of String.endsWith() or String.startsWith() eg. str.contains("omar");

  3. How to quickly search a large file for a String in Java?

    Apr 28, 2016 · I am trying to search a large text file (400MB) for a particular String using the following: File file = new File("fileName.txt"); try { int count = 0; Scanner scanner = new Scanner(file); while(scanner.hasNextLine()) { if(scanner.nextLine().contains("particularString")) { count++; System.out.println("Number of instances of String: " + count ...

  4. Java 8 – How to find a ‘STRING’ in a Text File? - Techndeck

    Jan 13, 2023 · Find String in a Text File using Java 8. Learn two different ways of how to check if a string is present in the text file in Java 8...

  5. Java Program to Search for a File in a Directory

    Oct 21, 2020 · Searching files in Java can be performed using the File class and FilenameFilter interface. The FilenameFilter interface is used to filter files from the list of files. This interface has a method boolean accept(File dir, String name) that is implemented to find the desired files from the list returned by the java.io.File.list() method.

  6. How to search for a string in a file using Java regular expression.

    Here is a simple example that demonstrates how you can use Java regular expression to find a string or a phrase in a text file. public List searchString(String fileName, . String phrase) throws IOException{ Scanner fileScanner = new Scanner(new File(fileName)); int lineID = 0; List lineNumbers = new ArrayList();

  7. Search String in File with Java as fast as possible - Medium

    Sep 18, 2021 · There are lots of different ways. Let’s see what is the best solution. Environment: ~1GB text file with ~6 million rows. Let’s start from the easiest one; the standard “read all files in memory...

  8. Find Strings Within a Text File in Java - Online Tutorials Library

    Sep 10, 2019 · Learn how to find strings within a text file using Java. This guide covers essential methods and examples for efficient string searching.

  9. java - Fast way of searching for a string in a text file - Code …

    Mar 11, 2014 · When searching for a fixed string (i.e., no wildcards), Knuth-Morris-Pratt is significantly faster than naive matching, for example. This could probably make a difference, use StringBuilder stackoverflow.com/questions/4645020/… Fast comes at a price.... code complexity and perhaps readability.

  10. Search a Text File in Java : The Coders Lexicon

    Apr 16, 2008 · The user will be able to type something like java searchfile “hello” and it will search our text file for the phrase “hello” and return the position and line number where the word appears. We do this by opening up a file using a specialized Java class called a “BufferedReader”.

Refresh