473,388 Members | 1,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Merging/Appending two file in java

Hai friends,
I have two .ixf files
My intention is to merge/ Append both to one.
Could any one help me to find a way. i tried this forum though i coud not find anything yet.
Thanks
Priyan
Apr 28 '09 #1
10 22336
r035198x
13,262 8TB
First you need to know what an ixf file is. I think you can get the specification from the IBM DB2 sites.
Then you can read it using the appropriate API.
Apr 28 '09 #2
it does not matter, any two files. i wanted to append one to another.
May 10 '09 #3
r035198x
13,262 8TB
How you read/write to files in Java depends on the file formats of the files.
May 11 '09 #4
Thanks for messages.
i have 100s of files in Dir1 & Dir2. but they have same files, but contents are different. files have extension of *.ixf.

I l explain here
1- Read the contents of file1 which is in Dir1
2- Read the contents of file2 which is in Dir2

then add the contents of the file2 to the end of he file1 which is in Dir1.

i tried some codes, which is not successful. if you can , guide with some codes, as i am new to Java, it will be a great hint for me to understand the problem.

thank
Priyan
May 11 '09 #5
r035198x
13,262 8TB
What API are you using to read the files? Do you know the structure of the ixf files?
May 11 '09 #6
NetBeans IDE 6.5

the format looks like
1., 3.
4., 2.
5., 4.
9., 3.
10., 6.
12., 1.
13., 1.
14., 4.
16., 10.
May 11 '09 #7
r035198x
13,262 8TB
NetBeans is just an IDE not an API.
Are you sure that is the format? Verify the correct format by searching it from the IBM site.
If the file is simple textual file like you are alluding to, then you can do this easily using FileReader and FileWriter API.
May 11 '09 #8
hai,
i able to come up to this part, and now i am worried where to give the file names.
if this part is ready, then we can move to the directory part.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. mport java.io.*;
  4. import java.io.FileInputStream;
  5.  
  6. public class CopyFile{
  7.     private static void copyfile(String srFile, String dtFile){
  8.         try{
  9.             File f1 = new File(srFile);
  10.             File f2 = new File(dtFile);
  11.             InputStream in = new FileInputStream(f1);
  12.  
  13.  
  14.             OutputStream out = new FileOutputStream(f2,true);
  15.  
  16.             byte[] buf = new byte[8192];
  17.             int len;
  18.             while ((len = in.read(buf)) > 0){
  19.                 out.write(buf, 0, len);
  20.             }
  21.             in.close();
  22.             out.close();
  23.             System.out.println("File copied.");
  24.         }
  25.         catch(FileNotFoundException ex){
  26.             System.out.println(ex.getMessage() + " in the specified directory.");
  27.             System.exit(0);
  28.         }
  29.         catch(IOException e){
  30.             System.out.println(e.getMessage());            
  31.         }
  32.     }
  33.     public static void main(String[] args){
  34.         switch(args.length){
  35.             case 0: System.out.println("File has not mentioned.");
  36.                     System.exit(0);
  37.             case 1: System.out.println("Destination file has not mentioned.");
  38.                     System.exit(0);
  39.             case 2: copyfile(args[0],args[1]);
  40.                     System.exit(0);
  41.             default : System.out.println("Multiple files are not allow.");
  42.                       System.exit(0);
  43.         }
  44.     }
  45. }
  46.  
  47.  
May 11 '09 #9
hai,

Actually its a query result which is stored in a file. query was executed with IBM DB2.

we don't need to worry about the content of the file that much. its just textual.
if you can give more suggestions with my code which i have given, might help me in get in further.
thnaks
May 11 '09 #10
JosAH
11,448 Expert 8TB
@svpriyan
Appending a file to another one is easy: have a look at the constructors of the FileWriter class: two of them make the writer append to an already existing file.

kind regards,

Jos
May 11 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
0
by: Nathan Coast | last post by:
Hi, I need to merge the contents of an xml file with xml elements that have been generated into another file. What I'm actually trying to do.... I'm updating the maven tomcat plugin. This...
0
by: decrypted | last post by:
I wrote some code to save layout of forms in my application to an XML File. One of the forms has a control which can emit its own layout in the form of XML....so for this controls, I obviously just...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
2
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
2
by: Thanya Teutschbeim | last post by:
I'm trying to use DataSet.Merge, but it works like an Append, and I don't want this. I want to update dataset data. I have two files with same fields and the same xml schema. For example: File...
1
by: Emmanuel | last post by:
I am writing java application which will store data in XML file..Each time when i execute that program ,previous data will be overidden.. Is it possible to append data to XML file,if anybody knows...
2
by: Tom Costanza | last post by:
For the life of me, I can't seem to merge main menu items from child to parent with MDI forms. I can merge sub-menus, but not main menu items. So I have a parent form with: File Windows Help...
7
by: Jeff | last post by:
I am new to VB.net 2005 in visual web developer, and even newer to Javascript. I need a java alert box that contains text that eventually will come from an sql table. The alert box should...
0
by: ErikaW | last post by:
Hi all, I've tried to google this but could not find a clear solution. I have a Web application developed in JDevloper using mostly html and Javascript. I have a pre-defined PDF form which I merge...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.