java - How can I search a sentence in a file? -
i trying search program.
 don't know how search sentence in file.
in c# can use linq, in java don't know.
java loves difficult in both line-based , token-based scanning.
heres example of line based scanning sentence:
public static boolean scanfile(string sentence) {     scanner linescan = new scanner(new file("filename.txt"));     while (linescan.hasnextline()) {         if (linescan.nextline().contains(sentence)) {             return true;         }     }      return false; } and heres example of token based scanning word:
public static boolean scanfile(string word) {     scanner linescan = new scanner(new file("filename.txt"));     while (linescan.hasnextline()) {         scanner tokenscan = new scanner(s.nextline());         while (tokenscan.hasnext()) {             if (tokenscan.next().equals(word)) {                 return true;             }         }     }      return false; } 
Comments
Post a Comment