copy elements from a file to another file

A

Andrea

Hi,I hope someone will help me because I have a problem. I have 2
files.txt. I have to take one element contained in a row of the first
file and find it in the second file.
If in the second file I find the element I want copy the row in which
there is the element and the 9 previous rows. So, in the second file I
will be 10 rows; the last
rows contained my element.


void WriteData (String GPSCANfile,String SPHfile)
{
try
{
BufferedReader gpscanf = new BufferedReader (new FileReader
(GPSCANfile));
BufferedReader sphf = new BufferedReader (new FileReader
(SPHfile));
BufferedWriter file = new BufferedWriter (new FileWriter
("Data.txt"));


.........
}



Someone can help me,please????
Thanks everybody
 
L

Luc The Perverse

Andrea said:
Hi,I hope someone will help me because I have a problem. I have 2
files.txt. I have to take one element contained in a row of the first
file and find it in the second file.
If in the second file I find the element I want copy the row in which
there is the element and the 9 previous rows. So, in the second file I
will be 10 rows; the last
rows contained my element.


void WriteData (String GPSCANfile,String SPHfile)
{
try
{
BufferedReader gpscanf = new BufferedReader (new FileReader
(GPSCANfile));
BufferedReader sphf = new BufferedReader (new FileReader
(SPHfile));
BufferedWriter file = new BufferedWriter (new FileWriter
("Data.txt"));


.........
}



Someone can help me,please????
Thanks everybody

Just take then entire file you need to search through and drop it into a
linked list of Strings (assuming it is sufficiently small, which it
definitely sounds like it is)

I see the code you cut and pasted, so it looks like you have the majority of
the work done already!
 
L

Luc The Perverse

Andrew Thompson said:
Only you can help that multi-posting problem, by not doing it.


EEk! I tried to help that man - I didn't know that he was an evil multi
poster.
 
P

Patricia Shanahan

Luc said:
Just take then entire file you need to search through and drop it into a
linked list of Strings (assuming it is sufficiently small, which it
definitely sounds like it is)

I see the code you cut and pasted, so it looks like you have the majority of
the work done already!

If it is too big for reading it into a list to make sense, consider
using java.util.Queue interface, with a LinkedList implementation. You
could read the first nine lines and push them onto the queue.

From then on, as you read a line, if it the line you want the queue
contains the nine previous lines you need to output. If it isn't, remove
the first line from the queue and add the new one.

You could effectively do the same thing yourself using a nine element
String array and some circular buffer logic, but it would be a lot more
work.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top