ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to append a text file in between an existing file

Post new topic  Reply to topic
 How to append a text file in between an existing file « View previous topic :: View next topic » 
Author Message
bhavyabhandari
PostPosted: Tue May 22, 2007 9:26 am    Post subject: How to append a text file in between an existing file Reply with quote

Apprentice

Joined: 09 Nov 2006
Posts: 33

I have a query ..

I have a text file say a.txt which contains a header,data and a trailer.
I have another text file say b.txt which has some data,
Now i have to append the content of b.txt below the data part of a.txt
using Java compute node in Messg Broker..

How should i go about to append the file b.txt in between the file a.txt..
Back to top
View user's profile Send private message Yahoo Messenger
jbanoop
PostPosted: Tue May 22, 2007 9:29 am    Post subject: Reply with quote

Chevalier

Joined: 17 Sep 2005
Posts: 401
Location: SC

Use the file handling API of Java. Open the target file in read-write mode, move to the location after which you need to do the inserts .. write the contents you want to the file (by reading from the other file and writing to the target).

Should be possible.
Anoop
Back to top
View user's profile Send private message Yahoo Messenger
bhavyabhandari
PostPosted: Tue May 22, 2007 9:33 am    Post subject: The code.. Reply with quote

Apprentice

Joined: 09 Nov 2006
Posts: 33

The code I have used ::

int count = 0;
FileReader fileReader = new FileReader(record);
BufferedReader br = new BufferedReader(fileReader);
while ((record = br.readLine()) != null)
{
count++;
}



System.out.println(count); // gives the total no. of,lines.
count = count-2; // the line where i have to append the text file b.txt

How should i append it here??
Back to top
View user's profile Send private message Yahoo Messenger
jbanoop
PostPosted: Tue May 22, 2007 9:41 am    Post subject: Reply with quote

Chevalier

Joined: 17 Sep 2005
Posts: 401
Location: SC

use the java.io.RandomAccessFile.
http://java.sun.com/j2se/1.5.0/docs/api/java/io/RandomAccessFile.html


Anoop.
Back to top
View user's profile Send private message Yahoo Messenger
bhavyabhandari
PostPosted: Tue May 22, 2007 9:51 am    Post subject: a little more help Reply with quote

Apprentice

Joined: 09 Nov 2006
Posts: 33

Could you help me a bit to explain it through a coded perspective if possible..
Back to top
View user's profile Send private message Yahoo Messenger
jbanoop
PostPosted: Tue May 22, 2007 10:18 am    Post subject: Reply with quote

Chevalier

Joined: 17 Sep 2005
Posts: 401
Location: SC

* read contents of b.txt into a byte[] using regular file read operations.
* create new RandomAccessFile for a.txt opened in "rw" mode
* move file pointer (seek(int numBytes) ) to the location you want to insert the new content
* insert content using write(byte[]) method.

Anoop
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to append a text file in between an existing file
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.