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 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









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
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
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
Count lines of a particular file
In this program you will learn how to read a file and count number of lines... and count no of lines in a file. Program first asks the user to enter.... Its reads the file(s) and then prints the no of lines in each file. Java
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... the user typed his/her name, it will check the name in the text file. To check
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
Java - search/find a word in a text file - Java Beginners
Java - search/find a word in a text file  Hello, I would like... to search them for a word. The word will be PASS or it can be FAIL. If PASS I want to do nothing, if FAIL, I want to record in 1 master output file, the name
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
Java file number of lines
Java file number of lines In this section, you will learn how to count the number of lines from the given file. Description of code: Java has provide... of the file. We have used counter here to detect the number of lines occurred
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
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
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... i want to update the quantity in my text file, if the item i entered matches... 150 .... ....20 lines. java code: import java.io.*; import java.util.*; class
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
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
File download return value - Java Beginners
File download return value  How to get the return value of Open/Save/Cancel buttons in a File Download pop up using javascript
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
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
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
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
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
php file search
php file search  How to search file in PHP .. $dir = '/tmp
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
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
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
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
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
php search file
php search file   I wanted to write a php script to list all the files available in either folder or sub folder
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  
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 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
Text File I/O - DVD.java - Java Beginners
Text File I/O - DVD.java  NEED HELP PLEASE. The application should use a text file with one value on each line of the file. Each movie would use three lines: one for title; one for studio; one for year. When the application
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
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
JavaScript write to text file
JavaScript write to text file  ... are going to create a file and write text into it using JavaScript. In the given example... to write the text into the created file, we have used WriteLine() method. This code
Converting Text Files into Bzip File
Converting Text Files into Bzip File  Hi, I am facing the problem during run the program, when converting text files into Bzip file. Please guide me how do i convert the text file into bzip file in PHP. I will welcome, if anyone
how to sort the text file and display it in jtable
how to sort the text file and display it in jtable   my text file is: contig00001 length=586 numreads=4... ctgaggactcctcg i want to display the lines started with ">" symbol to be displayed

Ads