How to Append two  word documents into single  using   java

How to Append two word documents into single using java
we tried this but it's not append the one word document to other
source code:public class AppendTwoWordFiles {
     public static void main(String []arg)throws IOException
          FileInputStream fi=null;
          FileOutputStream fo=null;
          try {
               System.out.println("Enter the source file name u want to append");
               BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
               File f1=new File(br.readLine().toString());
               System.out.println("Enter the Destination file name ");
               File f2=new File(br.readLine().toString());
               fi = new FileInputStream(f1);
               fo = new FileOutputStream(f2,true);
               byte b[]=new byte[2];
               while((fi.read(b))!=-1);
          fo.write(b);
System.out.println("Successfully append the file");
          } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          finally{
          fi.close();
          fo.close();
plz reply me quickly ,,,what can i follow

Use this code ..
and give the path of the both file like this.....
source file ---- C:/workspace/Practice/src/com/moksha/ws/test/practice.text
destination file ---- C:/workspace/City/src/com/moksha/ws/test/practice1.text
import java.io.*;
public class AppendTwoWordFiles {
     public static void main(String[] arg) throws IOException {
          FileInputStream fi = null;
          FileOutputStream fo = null;
          try {
               System.out.println("Enter the source file name u want to append");
               BufferedReader br = new BufferedReader(new InputStreamReader(
                         System.in));
               File f1 = new File(br.readLine().toString());
               System.out.println("Enter the Destination file name ");
               File f2 = new File(br.readLine().toString());
               fi = new FileInputStream(f1);
               fo = new FileOutputStream(f2, true);
               byte b[] = new byte[2];
               int len = 0;
               while ((len = fi.read(b)) > 0) {
                    fo.write(b, 0, len);
               System.out.println("Successfully append the file");
          } catch (FileNotFoundException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          } finally {
               fi.close();
               fo.close();
}

Similar Messages

  • How to merge two movies documents into 1 in  iTunes?

    Can anyone tell me how to merge two movies documents into one in iTunes? Sorry maybe this is an easy and dumb question for you, but I have totally no idea. I download some movies in Windows and use Kigo Video Coverter to converte them into mp4 format. So I can watch it through new Apple TV in my big screen TV. Now I am thinking maybe I can upgrade my experience a bit more. Because some movies are downloaded into 2 or 3 separated document and I have to choose and click them while seeing. Is there any software can merge those separated documents into one single in mp4 format? I wish you could give me several to choose . Freeware is better. Thanks in advance.

    Thanks. I've tried simplemovies application but it seems too much complicated for me. I read some passages online and bought Quicktime Pro ($30) and finally link 2 mp4 documents together. So easy. Only issue is I have to pay $ 30 .

  • I want to know how to turn a word document into a jpeg so I can put the document on Facebook as a picture. I have made posters and if I do a print screen they are unable to be read, or if i turn it into a PDF there is no save as jpeg??

    I want to know how to turn a word document into a jpeg so I can put the document on Facebook as a picture. I have made posters and if I do a print screen they are unable to be read, or if i turn it into a PDF there is no save as jpeg??

    iOS device backups are stored in your iTunes library.
    Move your iTunes library to an external drive.

  • How to convert a word document into the PDF format?

    Please instruct me step by step on how to convert several Word documents into the PDF format?

    If properly installed and updated (depending on the WORD version), you can simply do any of the following:
    1. Open the doc in WORD and select Print, choose the Adobe PDF printer, print.
    2. Open the doc in WORD and go to the Acrobat menu in WORD and select create PDF (this uses PDF Maker).
    3. Open the doc in Acrobat and the conversion should be done based on PDF Maker.

  • Idea  about convert word document to pdf using java api

    idea about convert word document to pdf using java api if any one find it mail me at [email protected]

    api if any one find it mail me at
    [email protected]
    What happend to your other mailID :
    [email protected] ????
    http://forum.java.sun.com/thread.jspa?threadID=639851&
    messageID=3756910It received the Spam Of Death. RIP

  • Insert One Word Document into another using OLE ABAP

    Hi,
    I want to insert one word document into another Word Document called by OLE ABAP.
    ie.first word document having 6 pages have been displayed and I want first page of
    second document as a 7th page.I want to dispaly the entire data in  one document.
    Hope to get the reply soon.
    Thanks & Regards,
    Divya.

    T.code :- DWDM
    u can check OLE and OFFICE INTEGRATION tree  have so many demo report
    Report :- RSOLETT1
    Edited by: Krupaji on Feb 18, 2010 2:00 PM

  • Appending MS-Word documents into one document.

    Greetings,
    I've used the MS-Office VI's to create MS-word documents using a .dot template.   It is very handy and provides very good results with little effort.  
    For various intended reasons I create in number of one page documents.
    Anyone know how to append .doc files into one .doc file?  Any active-x commands able to do this?  
    Any help would be appreciated.
    Modemmad99

    Check out this other discussion forum post. It will show you how to use Active X commands or Report Generation Toolkit VIs to append documents together.
    Stephanie O.
    DIAdem Product Manager
    National Instruments

  • How to pass a Word Document into a byte array?

    Hi All
    I have an application wherin i select multiple files and send them over to a webservice method.The files selected are zipped internally and sent across as a single entity.
    I could pass the files and retrieve them using my test tool to check thir successful send and retrieval as long as the files were in "text" format.
    But now i need to figure a way out to pass word docs or any other content types.I tried passing word docs in the mechanism that works fine for "text" files.But when i retrieve the files,and try to open the word documents the MS Word states that "the file is corrupt and cannot be opened". The following is the code.
    public byte[] getContent(IDfSessionManager sessionManager,String repositoryName, String objectIdString) {
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       StringBuffer sb = new StringBuffer("");
        try {
              System.out.println("Repository Name " + repositoryName);
               mySession = sessionManager.getSession(repositoryName);
               // Get the object ID based on the object ID string.
                DfId dfId = new DfId(objectIdString);
                 if (dfId.isObjectId())
         System.out.println("Successfully fetched id " + dfId);
              IDfSysObject sysObj = (IDfSysObject) mySession.getObject(dfId);
              System.out.println("Content Type ++++++ " + sysObj.getContentType());
              ByteArrayInputStream buf = sysObj.getContent();
              int i = 0;
             InputStreamReader readInput = new InputStreamReader(buf, "UTF8");
             BufferedReader br = new BufferedReader(readInput);
             while (br.ready()) {
            sb.append(br.readLine());
             sb.append("\n");
              String captureText = sb.toString();
         try {
         is = new ByteArrayInputStream(captureText.getBytes("UTF-8"));
                         } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
         final int BUF_SIZE = 1 << 8; // 1KiB buffer
         byte[] buffer = new byte[BUF_SIZE];
                    int bytesRead = -1;
                     while ((bytesRead = is.read(buffer)) > -1) {
         outputStream.write(buffer, 0, bytesRead);
         is.close();
         System.out.println("This is byte acquisition ###### >>>>>>>>>>>>>>>>>>>");
         binaryData = outputStream.toByteArray();
         File temp1 = File.createTempFile("Test",".docx");
         FileOutputStream fos = new FileOutputStream(temp1);
         fos.write(binaryData);
         fos.close();
              // Handle any exceptions.
              catch (Exception ex) {
              ex.printStackTrace();
              finally {
                   sessionManager.release(mySession);
              return binaryData;
         }I assume that UTF8 must be applicatbe only to deal with .txt files.
    I would really appreciate your guidance to obtain a way to acquire data from word documents so that i could open and read them without errors.
    Thank You
    Regards

    Hi B1J001
    Following your suggestion i curtailed the code as follows:
    public byte[] getContent(IDfSessionManager sessionManager,String repositoryName, String objectIdString) {
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       StringBuffer sb = new StringBuffer("");
        try {
              System.out.println("Repository Name " + repositoryName);
               mySession = sessionManager.getSession(repositoryName);
               // Get the object ID based on the object ID string.
                DfId dfId = new DfId(objectIdString);
                 if (dfId.isObjectId())
         System.out.println("Successfully fetched id " + dfId);
              IDfSysObject sysObj = (IDfSysObject) mySession.getObject(dfId);
              System.out.println("Content Type ++++++ " + sysObj.getContentType());
              ByteArrayInputStream buf = sysObj.getContent();
              *String testbuf = buf.toString();*
              *testbytearray = testbuf.getBytes();*
            File temp1 = File.createTempFile("Test",".docx");
            FileOutputStream fos = new FileOutputStream(temp1);
            fos.write(testbytearray);
            fos.close();
         // Handle any exceptions.
         catch (Exception ex) {
         ex.printStackTrace();
         finally {
         sessionManager.release(mySession);
         return testbytearray;
         }I am using just the ByteArrayInputStream to access the content. Still my attempt to open the document from the temporary file yields "file corrupt message".Am i going the right path?
    Thank You
    Regards

  • How to compare two huge xml files(50MB+) using Java Code

    I want to compare two huge xml files using java code and need to find the difference of those xml files
    is there any API for that

    You should find third party API

  • How to integrate two Siebel Applications into single app UI

    Dear All,
    Currently we have a Siebel application which is running with various Siebel modules. Like for example in one single application object manager we are having various screens and views related to various modules like UCM, Loyalty, Marketing etc.
    But due to some operational reasons, we would like to deploy few modules as applications on different machines.For example we will install a separate Marketing application on a server and loyalty on a separate server.
    How can we integrate all these applications installed in different different machines in a single App Object Manager to provide a single UI interface for the user.
    So even after segregating into different applications, we would like to have single app UI for user.
    Please suggest if it already being implemented in such a way anywhere.
    Regards

    Hello...
    Siebel offers many great options to help you implement your business needs. siebel bookshelf is very well documented...we can also connect you with a few great system integrators that could help you architect your siebel implementation? best wishes for this holiday season...
    Regards,
    Sylvia Fong Ny- GERMAIN SOFTWARE - Performance Monitoring Software for Siebel CRM
    21 Columbus Avenue, Suite 221, San Francisco, CA 94111, USA
    [email protected], http://www.germainsoftware.com

  • How do I combine two pdf documents into one using preview?

    If I remember correctly I have done this in the past but now I can't remember how to do it.
    Message was edited by: admiral_koa
    i finally found some other questions like mine which got answered. So I'm closing this out.

    That would be kind of you. Thank you. This is my first post on the new support setup. I find it a lot different than the previous arrangement. Harder actually.  I don't remember what I did when I first posted it. It seemed like my searches for my subject I could not find until I posted my question and then I found some immediately. Evidence of my struggling with how this works.
    thanks again,
    AK

  • How read a particular word in a file using java

    Hi.. friends
    I have one problem with reading contents of a file.
    can u give me the source code
    how to read a data from file
    example.
    ss.txt this file contains following data..
    Another Important thing to remember is that the
    instance variables are created and initialzied.
    now the thing is
    i wanted to find words like.. remember, instance
    from ss.txt
    please help me.
    Thnx..

    Read a data from file:
    public void getFileContents() throws Exception
            BufferedReader rdr =
                    new BufferedReader(
                    new InputStreamReader(
                    new FileInputStream(xmlFileName)));
            System.out.println("Reading from file....:" + xmlFileName);
            StringBuffer contents = new StringBuffer();
            String line = null;
            while((line = rdr.readLine())!= null)
                contents.append(line);
        }

  • How to add DTD syntax line into XML using java code

    Hi,
    I am building xml file with java, usiing document.createElement()
    and document.appendChild(element),
    like that
    now i need to add dtd file path and synatx in the top of the xml file,
    how can i do it through java code
    any body could help me
    i appreciate your help.
    thanks
    Durga

    Hi Suneetha,
    Thanks for your reply..
    Now i am getting docType in xml file but not in the format of what i want
    please look at my code
    i need
    <!DOCTYPE myRootElement SYSTEM "myXMLDTD.dtd" >
    but i am getting
    <!DOCTYPE myRootElement PUBLIC "" "myXMLDTD.dtd">
    There is change i need to get the SYSTEM in place of PUBLIC and i need to get rid of "" code between dtd and PUBLIC
    for this i am doing in my code as
    DocumentType theDocType = new DocumentImpl().createDocumentType ("SYSTEM","","myXMLDTD.dtd");
    Document theDoc = new DocumentImpl(theDocType);
    i dn't know what is the wrong ? i dn't know what are the parameters at what place to pass if you know any thing just let me know
    thanks in advance
    and i apperciate you help.
    Durga

  • Loading Word document into Adobe Captivate

    I would like to know how to upload MS Word document into Adobe Captivate format.

    Hi there,
    Welcome to Adobe Community.
    Could you please elaborate a little more on what exactky you are trying to do?
    You can open a word document on a button or on an object but you cannot import it. You can import a PowerPoint Slide.
    Thanks!

  • Merge two word documents

    Hi All,
    I have a requirement to merge two word documents into one word document. I will upload both the documents from presentation server and have to merge both the documents into 1 word document and save in in SAP.
    Is it possible to merge two word documents?
    Thanks,
    Amit

    Same requirement i posted earlier
    check this

Maybe you are looking for