Search and return lines of text file

Ads
 

Search and return lines of text file

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;

} } "

View Answers

Ads









Related Tutorials/Questions & Answers:
Search and return lines of text file
Search and return lines of text file  I wrote the following code, that found lines of txt file with contains certain word, but it returns only...)) { System.out.println(line); RL = line; //return "Lines: "+RL; (if I write
Read Lines from text file
Read Lines from text file  Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines from a text files and split each line based on a predefined size... Eg : If the 1st line of the text file
Advertisements
To dump 10lakh lines from a text file to a mysql table
To dump 10lakh lines from a text file to a mysql table  I need to dump a text file datas -100000 lines into a mysql table.i'm able to dump only 152000 lines only
Java search text file
Java search text file In this tutorial, you will learn how to search a text... the name of a text file to search for. If the name does not have a .txt extension, display an error message. Then search the file in the current directory
Java Read Lines from Text File and Output in Reverse order to a Different Text File
Java Read Lines from Text File and Output in Reverse order to a Different Text File  I need to read a file that was selected by the user using... to another text file. When that is done the output values of that file need
binary search tree from text file
binary search tree from text file  How so I go about constructing a binary search tree from a text file, which has letters and numbers, which must be sorted and printed in ascending order. E.g. Text file contents 3 apples pears
Java search word from text file
Java search word from text file In this tutorial, you will learn how to search a word from text file and display data related to that word. Here, we have created a text file student.txt which consists of id, name and marks of few
display repeated lines in a file
display repeated lines in a file  i want a java program that accepts file from user and displays the repeated lines in a file
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
delete lines in the file
delete lines in the file   I am using a file as Input in program...The file contains round about 1,00,000 lines .My program after each iteration takes a data from that file at process it. My Question is when a particular data
Delete specific lines from text in Java
Delete specific lines from text in Java  Hi, beginning in java, i'm trying to delete specific line from a text file. Ex: i want to delete data between line 10 and 20 and between line 20 and 30. or i want to specify line
Java read lines from file
Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line... of reading file line by line in Java. Can any one share me the code for reading
text file
text file  Hello can I modify the program below so that all the numerical data is stored in an external text file,that is the data contained...=description; this.price=price; } public String getCode(){ return code; } public
text file
text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should... at the start of the program from a seperate external text file.Thank you! mport
Sorting text file
Sorting text file  Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value... according to begin value. Text File having list like this: 5| 3| can anyone
Full-text Search
Full-text Search  I need a java source code to impliment a full-text search in java web application using servlets with firebird database
Full-text Search
Full-text Search  I need a java source code to impliment a full-text search in java web application using servlets with firebird database
Reading a text file in java
Reading a text file in java  What is the code for Reading a text file... in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks
in unix which command is used to sort the lines of data in a file in reverse order
in unix which command is used to sort the lines of data in a file in reverse order  in unix which command is used to sort the lines of data in a file... the lines of data in a file in reverse order
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
Steps to read text file in pyspark
Steps to read text file in pyspark  Hi, I am learning to write program in PySpark. I want to simply read a text file in Pyspark and then try some code. What are the Steps to read text file in pyspark? How much time it takes
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
uploading a text file into a database
uploading a text file into a database  how to upload a text file... { static File file; public static void main(String[] args) throws Exception { JLabel label=new JLabel("Choose File
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix  Hi, I am... terminal to find a text in all the files in all directories? how to search... the file containing this text. I will find in all the files/directories from
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix  Hi, I am... terminal to find a text in all the files in all directories? how to search... the file containing this text. I will find in all the files/directories from
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix  Hi, I am... terminal to find a text in all the files in all directories? how to search... the file containing this text. I will find in all the files/directories from
how to search a text in all files in a folder in unix
how to search a text in all files in a folder in unix  Hi, I am... terminal to find a text in all the files in all directories? how to search... the file containing this text. I will find in all the files/directories from

Ads