
I wrote the following code, that found lines of txt file with contains certain word, but it returns only the first or the last line! (However, the System.out.println show me all the lines with the word! ) Where is the problem?!
Thank U :)
"import java.io.*;
public class SearchString {
String RL;
public String SearchString(String pathFile, String str) {
try {
BufferedReader in = new BufferedReader(new FileReader(pathFile));
String line = in.readLine();
while (line != null) {
if (line.contains(str)) {
System.out.println(line);
RL = line;
//return "Lines: "+RL; (if I write it the program copy only the first line) }
line = in.readLine();
}
} catch (IOException ex) { ex.printStackTrace(); }
return "Lines: "+RL;
} } "
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.