Hi,
My requirement is i have a file which has many records. I have to filter the records that has a text "AGR" and write only those records to a different file.
Can anyone please help me out URGENT?
Thanks,
Priyanka.
Printable View
Hi,
My requirement is i have a file which has many records. I have to filter the records that has a text "AGR" and write only those records to a different file.
Can anyone please help me out URGENT?
Thanks,
Priyanka.
Show some code. What have you tried already and where are you stuck? Nobody here is going to write your code for you.
We don't need to know that your program is urgent to you,
Your post is not more important than others.
What have you done so far?
I have written a code to read and write the contents to another output file. But i am not sure how to search a particular text in a record and write that record alone.
import java.io.*;
public class rFile {
public static void main(String[] args) throws IOException {
File inputFile = new File("/Users/t/t.txt");
File outputFile = new File("/Users/t/t2.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
1.) What do you mean by record? Do you mean line?
2.)Wrap that FileReader with a BufferedReader and use the readLine method to read line by line.
3.) Use a PrintWriter to write the new file.
4.) flush after you are done writting and close in finally blocks.
Yes record is a line. I can read line by line. But in a line i have a text say "ABC" if i have a line with that text then i have to write that lines alone to the new file.
Read the API specs for the String.contains method.
Implement all the suggestions I suggested above.
r035198x rox
haha :p i can't wait!