Wpis z mikrobloga

Mireczki od Javy, help pls.

Chciałbym, aby przy tworzeniu obiektu ponizszej klasy powstawal String z pliku, ktory biorę z podanej sciezki. Wiem, że moja pętla dodaje kolejne linijki tekstu, ale jak dopisac je do String txtFile, abym mogl pozniej stworzyc metodę wyszukującą podaną frazę / słowo?

public class Finder {

private String txtFile;

public Finder(String path) throws IOException {

FileReader fileReader = new FileReader(path);
BufferedReader bufferedReader = new BufferedReader(fileReader);

while ((txtFile = bufferedReader.readLine()) != null) {

}

bufferedReader.close();

}

// public int getStringCount(String word) {
//
// Pattern p = Pattern.compile(word);
// Matcher m = p.matcher(txtFile);
// int count = 0;
// while (m.find()) {
// count += 1;
// }
//
// return count;
//
// }

}

#java #naukaprogramowania
  • 2