For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2006 > copy elements from a file to another file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author copy elements from a file to another file
Andrea

2006-07-19, 7:02 pm

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

Tobias Schröer

2006-07-20, 4:04 am

Hi,

Andrea schrieb:
> 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.

[...]

I would suggest that you read the two files in two lists that contain
your elements, which are the files' rows as I understand it. Do your
s and copy operations on those lists and finally write back the list
content to your files.
Apart from a easier handling, the lists are much faster than file I/O
operations.

Tobi
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com