Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

copy elements from a file to another file

Thread view: 
Andrea - 19 Jul 2006 16:18 GMT
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
Luc The Perverse - 19 Jul 2006 16:35 GMT
> 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
[quoted text clipped - 20 lines]
> 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!

--
LTP

:)
Patricia Shanahan - 19 Jul 2006 22:00 GMT
>> 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
[quoted text clipped - 27 lines]
> 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
Andrew Thompson - 19 Jul 2006 18:10 GMT
> Hi,I hope someone will help me because I have a problem.

Only you can help that multi-posting problem, by not doing it.

Andrew T.
Luc The Perverse - 19 Jul 2006 18:28 GMT
>> Hi,I hope someone will help me because I have a problem.
> 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.

Signature

LTP

for( Base i : allYourBase)
       i.AreBelongToUs();



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.