title: Searching through a text file java
body: <p>So I am trying to search through a text file and if the user input is found, it returns the entire sentence including white spaces.But apparently I only get the first string and nothing pass the first string in the sentence. For example if i have a text file called "data.txt" and the contents in the first line is " I am a legend". after user enters "I am a legend" the output after the file is searched is "I". Any help would be appreciated.</p>
  
  <pre><code> public static void Findstr() { // This function searches the text for the    string
  
      File file = new File("data.txt");
  
       Scanner kb = new Scanner(System.in);
  
      System.out.println(" enter the content you looking for");
      String name = kb.next();
      Scanner scanner;
      try {
          scanner = new Scanner(file).useDelimiter( ",");
  
          while (scanner.hasNext()) {
              final String lineFromFile = scanner.nextLine();
              if (lineFromFile.contains(name)) {
                  // a match!
                  System.out.println("I found " + name);
                  break;
              }
          }
      } catch (IOException e) {
          System.out.println(" cannot write to file " + file.toString());
      }
  </code></pre>