Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Search and return lines of text file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Paola
Search and return lines of text file
0 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


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;

} } "


Advertisement
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
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
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... the lines from the file. You can see in the given example, we have created
php file search
php file search  How to search file in PHP .. $dir = '/tmp
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
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
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
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
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
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
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... in my text file, if the item i entered matches with item in text file.how can i... 150 .... ....20 lines. java code: import java.io.*; import java.util.*; class
click a word and search it from a file
click a word and search it from a file  i want to link a word with a file and search it form the file by clicking it. what could the code for this process
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
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
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
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
javascript code for search in html file
javascript code for search in html file  Hi, I am looking for javascript code through which we can search data with specific name find in any rows... e .......... Search: P002 After search result would be show like below format
 

 

 

DMCA.com