Problem while copying two files into same file

Hi,
I want to copy n number of files into the same file.I am using the below code for the purpose.
private void testFiles(){
          FileOutputStream fos = null;
          String file1  = "C:"+File.separator+"test1.doc";
          String file2 = "C:"+File.separator+"test2.doc";
          String file = "C:"+File.separator+"test123.doc";
          File testFile = new File(file);
          ArrayList arrFiles = new ArrayList();
          arrFiles.add(file1);
          arrFiles.add(file2);
          try {
                fos = new FileOutputStream(file,true);
               for(int i = 0; i < arrFiles.size();i++){
                    int ReadBytes = 0;
                    int BUFSIZ = 4096;
                    long fileSize ;
                    long copiedBytes=0;
                    String curFileName = (String) arrFiles.get(i);
                    File srcFile = new File(curFileName);
                    FileInputStream fis = new FileInputStream(srcFile);
                     fileSize = srcFile.length();
                    byte Buf[] = new byte[BUFSIZ];
                    while(copiedBytes < fileSize)
                         ReadBytes = fis.read(Buf, 0, BUFSIZ);
                         fos.write(Buf,0,ReadBytes);
                         copiedBytes +=ReadBytes;
                    System.out.println("copied files::"+curFileName);
               fis.close();
               fos.flush();
          } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } finally{
               try {
                    if(fos != null){
                         fos.flush();
                         fos.close();
               } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
     }Iam expecting that both the files will be copied sucessfully.But iam able to see only one file.But the file size of the destination file is the sum of both the source files copied.So that means the content is copied.Any ideas on possible causes/solutions.
Thanks in advance.

Hi,
Just a thought, if you build a sequence of inputstream using SequenceInputStream something like that
                String file1  = "C:"+File.separator+"test1.doc";
          String file2 = "C:"+File.separator+"test2.doc";
          FileInputStream s1 = new FileInputStream(file1); 
          FileInputStream s2 = new FileInputStream(file2);
          FileInputStream[] array = new FileInputStream[2];
          array[0] = s1;
          array[1] = s2;
          EnumerationImpl enumeration = new EnumerationImpl(array);
          SequenceInputStream sequence = new SequenceInputStream(enumeration);
               //code here the read to go through the sequence of inputstream and write them  into FileOutputStream
// and your Enumberation implementation class as below
public class EnumerationImpl implements Enumeration<FileInputStream> {
    private FileInputStream[] array;
    private int index;
    public EnumerationImpl(FileInputStream[] array) {
        this.array = array;
    public boolean hasMoreElements() {
        return index < array.length;
    public FileInputStream nextElement() {
        if (index < array.length) {
            return array[index++];
        throw new NoSuchElementException();
} Regards,
Alan Mehio
London, UK

Similar Messages

  • I can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name

    can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name. My original external has an error and needs to be reformatted but I dont want to lose this informations its my entire Itunes library.

    Sounds like the source drive is formatted as case sensitive and the destination drive is not. The preferred format for OS X is case insensitive unless there is a compelling reason to go case sensitive.
    Why can't you change the filename? Is it because the source drive is having problems?  If so is this happening with only one or two or a few files? If so the best thing would be to copy those over individually and then rename them on the destination drive.
    If it is more then you can do manually and you can't change the name on the source you will have to reformat the destination as case sensitive.
    Btw this group is for discussion of the Support Communities itself, you;d do better posting to Lion group. I'll see if a host will move it.

  • FCP Splits QT movie file into several files... problem and solution.

    Hi All,
    I was having problems exporting a QT movie (Video Only) of a 20 min Reel within a Feature Film I edited. The Database was quite large - the film was 2Hrs and Footage was about 12X.
    FCP would split the QT movie file into several files - only one of which was openable (either in FCP or the QT player). To my surprise, I also found that even though the file opened fine, I would get an error message when trying to copy it or its associated files over to another HD (Tiger would abort, after giving me an error No. and saying that there was an error while copying). The problem was repeatable and specific to this sequence.
    After some testing, I found that copying the clips (Video Only) to another sequence and re-exporting, seemed to solve the problem. My take on this is that too many ( > 12? ) Audio tracks causes problems in FCP when the database is large.
    But I do need these additional tracks. Any work arounds?
    Thanks,
    RD

    First, look in System Settings, and see if you've checked the box to limit file size to 2GB. Uncheck that box. See if that helps.
    Or it could just be a corrupt project causing the problem.

  • Problems while writing xml doc to a  file

    Hi all , in my project (of distributed xml databases) i need to write the xml files from the main server to the clients.
    These xml files i had formed by fragmenting one xml doc and i did the fragmentation using ....
    TransformerFactory tf = TransformerFactory.newInstance();
              Transformer transformer = tf.newTransformer();
              transformer.transform(new DOMSource(root),
              new StreamResult(new FileOutputStream(outputFile)));
    Now the problem is that on the client where these fragments reside..i m not able to do the indexing of the document properly ie...
    some extra text nodes with no values are coming in the index...
    i dont know how to deal wid the extra nodes that i m getting after parsing the file and craeting an index for the same..
    may be its coz of the transformer func i m using....don know(???)
    Note : i m fragmenting the xml files into text files using the above function and then sending thm to the client via sockets.
    Also,after fragmenting i am getting sumthng like
    <?xml version="1.0" encoding="UTF-8"?>
    in all the files..is this a source of any problem....
    plz reply soon....

    You have not described how you "index" the files and what you mean by that.
    Are you processing them with SAX or DOM, or one of the variations of those means?
    Is there a chance that the "extra" nodes are simply text nodes with newlines ("\n")? There are usually a lot of extra text nodes in a file each containing only one newline.
    If you are using SAX, there is no requirement for the parser to collect all of the text inside an element into a single block before calling the characters method. You may get several calls to characters between the start of an element and the end. If you change parsers, you may even get a different number of calls, but the character data will always be the same.
    Dave Patterson
    As to the <?xml version="1.0" encoding="UTF-8"?> line, that is perfectly fine. It means that your file thinks it is valid XML. Whether or not it REALLY is valid depends on a validation of the file.

  • Error while writing the data into the file . can u please help in this.

    The following error i am getting while writing the data into the file.
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="code">
    <code>null</code>
    </part>
    <part name="summary">
    <summary>file:/C:/oracle/OraBPELPM_1/integration/orabpel/domains/default/tmp/
    .bpel_MainDispatchProcess_1.0.jar/IntermediateOutputFile.wsdl
    [ Write_ptt::Write(Root-Element) ] - WSIF JCA Execute of operation
    'Write' failed due to: Error in opening
    file for writing. Cannot open file:
    C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing. ;
    nested exception is: ORABPEL-11058 Error in opening file for writing.
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation
    \WORKDIRS\SampleImportProcess1\input for writing. Please ensure 1.
    Specified output Dir has write permission 2.
    Output filename has not exceeded the max chararters allowed by the
    OS and 3. Local File System has enough space
    .</summary>
    </part>
    <part name="detail">
    <detail>null</detail>
    </part>
    </bindingFault>

    Hi there,
    Have you verified the suggestions in the error message?
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing.
    Please ensure
    1. Specified output Dir has write permission
    2. Output filename has not exceeded the max chararters allowed by the OS and
    3. Local File System has enough space
    I am also curious why you are writing to a directory with the name "..\SampleImportProcess1\input" ?

  • I have a mac book pro  OS 10.6.8.  I want to insert a .dmg file into a file i've copied to the MAC.  How do I do it?

    I have a mac book pro  OS 10.6.8.  I want to insert a .dmg file into a file i've copied to the MAC.  How do I do it?  Thanks

    Apple said that customers can still purchase a copy of Snow Leopard or Lion from its online store's telesales agents: 1-800-MY-APPLE (1-800-692-7753) or Customer Service and Sales Support at 1-800-676-2775. For Lion you'll get a redemptions code via e-mail and need to DL from the Mac App Store (requires SL 10.6.6+).

  • Problem while import u201CSAPKU60003 & SAPKNA7013u201D into SAP CRM 2007

    Gentlemen,
    I have a problem while import u201CSAPKU60003 & SAPKNA7013u201D into SAP CRM 2007,
    My current Support Package Level is:
    SAP_ABA       700     0015
    SAP_BASIS     700     0015
    PI_BASIS      2006_1_700     0006
    ST-PI     2005_1_700     0006
    CRMUIF         600     0003
    SAP_BW       700     0017
    SAP_AP                700     0012
    BBPCRM                600     0002
    First I had the following error:
       Syslog: k CQ3 : UMGSETTING&                                          rscpexcc 12
       GetDBMigrateCodePagesLangs uses TCP0D, TCPDB, TCP0C.
         0 entries from FUNCT (%/SAPCND/CNF_GET_RECORD_FROM_DB%) deleted.
         0 d /   0 i /   0 u /   6 = 100% ucf FUPARAREF
         6 entries for FUPARAREF imported (/SAPCND/CNF_GET_RECORD_FROM_DBA*).
         0 entries from RODIR (FUNC/SAPCND/CNF_GET_RECORD_FROM_DB) deleted.
         0 entries from RODIR (FUNC/SAPCND/CNF_GET_RECORD_FROM_DB) deleted.
         0 d /   0 i /   0 u /   1 = 100% ucf TFTIT
         1 entry for TFTIT imported (D/SAPCND/CNF_GET_RECORD_FROM_DB*).
       successfully set a temporary lock on table REPOSRC
       REPOS /SAPCND/LDETERMINATION$14                A replaced.
       REPOS /SAPCND/LDETERMINATIONU14                A replaced.
        [dev trc     ,00000]  Wed Nov 26 16:33:14 2008                         1315447  8.171484
        [dbdsoci.    ,00000]  *** ERROR => invalid offset 0 for placeholder 16
                                                                                    71  8.171555
       unsuccessful statement: EXEC SQL: SELECT ID,OBJECT,LANGU,TYP,VERSION FROM DOKIL WHERE (LANGU IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
       dsql_open returned with unexpected error code 2
       Please contact the SAP support.
       End of Transport (0016).
       date&time: 26.11.2008 - 16:33:14
       5 warnings occured.
       3 errors occured.
       Main import
       End date and time : 20081126163314
       Ended with return code:  ===> 16 <===
    After I got this error I upgraded the Kernel from patch level 159 to 179,
    After that I restarted the update again but the system is still running on u201CIMPORT_PROPERu201D and dose not given any update,
    From Import logs of the queue I can see the following,
       Summary:
        24 DOCUT imported.
        16 DYNPS imported.
        30 DYNPT imported.
       387 REPOS imported.
        43 REPOT imported.
       Totally 505 Objects imported.
       Totally 3636 tabentries deleted.
       Totally 14 objects activated.
       Totally 12229 tabentries imported.
       62066888 bytes modified in database.
        [dev trc     ,00000]  Wed Nov 26 18:14:19 2008                         20996974  40.917838
        [dev trc     ,00000]  Disconnecting from ALL connections:                   30  40.917868
        [dev trc     ,00000]  Disconnecting from connection 0 ...                  287  40.918155
        [dev trc     ,00000]  Closing user session (con_hdl=0,svchp=00000000003005B8,usrhp=00000000002FB748)
                                                                                  5759  40.923914
        [dev trc     ,00000]  Detaching from DB Server (con_hdl=0,svchp=00000000003005B8,srvhp=00000000061530E8)
                                                                                    921  40.924835
        [dev trc     ,00000]  Now I'm disconnected from ORACLE                    8230  40.933065
        [dev trc     ,00000]  Disconnected from connection 0                        90  40.933155
        [dev trc     ,00000]  statistics db_con_commit (com_total=527, com_tx=307)
                                                                                    59  40.933214
        [dev trc     ,00000]  statistics db_con_rollback (roll_total=0, roll_tx=0)
                                                                                    52  40.933266
       Disconnected from database.
       End of Transport (0004).
       date&time: 26.11.2008 - 18:14:19
       2 warnings occured.
       Main import
       End date and time : 20081126181419
       Ended with return code:  ===> 4 <===
    Please advice me.
    Regards,
    Ahmed

    I have similar problem while updating support packages in SAP R/3 4.6C environment. 
    000 unsuccessful statement: EXEC SQL: SELECT ID,OBJECT,LANGU,TYP,VERSION FROM DOKIL WHERE (LANGU IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,
    000 dsql_open returned with unexpected error code 1                                                                             
    000 unsuccessful statement: EXEC SQL: SELECT ID,OBJECT,LANGU,TYP,VERSION FROM DOKIL WHERE (LANGU IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,
    000 dsql_open returned with unexpected error code 1                                                                             
    Here is an outline of series of events that happened:-
    We are applying in support packages in SAP R/3 4.6C HR Development
    (TFI) environment. We planned with installing all the SP stacks
    starting from 1 to 9.
    -Updated kernel, tp , r3trans and SPAM level to latest level.
    We received the following error in Import_Proper step of Support
    package upgrade. Though the step has been repeated after making sure
    that we have all the required files at OS level, we go this error
    repeatedly.
    Main import
    Transport request___: SAPKB46C52
    System______________: TFI
    tp path : tp
    Version and Release: 305.13.25 46D
    check-sum error in datafile after 9374854 bytes.
    Main import
    End date and time : 20081205192603
    Ended with return code: ===> 16 <===
    When we renamed Co-File & data_file at OS level to see if the files are
    created again and reran we got the following error.
    Main import
    Transport request___: SAPKB46C52
    System______________: TFI
    tp path : tp
    Version and Release: 305.13.24 46D
    Main import
    End date and time : 20081205185117
    Ended with return code: ===> 12 <===
    We tried importing the individual support package SAPKB46C52 from STMS
    and the transport cancelled at an earlier step with the same error.
    Dictionary import
    Transport request___: SAPKB46C52
    System______________: TFI
    tp path : tp
    Version and Release: 305.13.25 46D
    check-sum error in datafile after 9374854 bytes.
    Dictionary import
    End date and time : 20081205195929
    Ended with return code: ===> 16 <===
    While playing around I have deleted the transport from the tp buffer
    and added manually, before doing so I made a backup of tp buffer at OS
    level and I got following error though I reverted back to backed-up
    copy.
    - Error in phase: IMPORT_PROPER
    - Reason for error: TP_BUFFER_INCONSISTENCY
    - Return code: 0008
    - Error message: Wrong sequence of Packages in the tp buffer (e.g.
    SAPKB46C52 )
    I then tried to disassemble the package separately and reran the
    import queue. Now I have RC 8 on that support package.
    When I did R3trans -l on the datafile it completed successfully.
    D:\>R3trans -l \usr\sap\trans\data\RB46C52.SAP
    This is R3trans version 6.05 (release 46D - 27.10.08 - 16:32:00).
    R3trans finished (0000).
    I verified the size of file "CSR0120031469_0023301.PAT" and it is the
    same as mentioned in SSP.
    Let us know is there is a workaround.

  • How do I merge 2 pdf files into one file?

    How do I merge 2 pdf files into one file?

    I use PrimoPDF (free download) to create pdf files. To merge two docs/pdfs/etc., print the first to a new pdf using Primo. Close it, then print the second and save it to the same new pdf. Primo gives you the option to 'append' or 'overwrite' the original file. By using 'append', you are just adding it to the back of the existing file. You can do this repeatedly to resort or combine existing pages into a new pdf.
    Also, I'm using Adobe Reader X.

  • How to convert wmf files into AU files?

    Does there exist anu utility to convert wmf audio files into AU files?

    You posted this same question 4 minutes ago.
    http://forum.java.sun.com/thread.jspa?threadID=770001&tstart=0
    Quit cluttering the forums.
    If you posted it by mistake, then reply to the posting stating so. In that way we don't get discussion going in two different threads.

  • Split TempDB Data file into multiple files

    Hey , 
    I have been seeing TempDB contention in memory on our SQL server 2012 Enterprise Edition with SP2 and I need to split TempDB Data file into multiple files .
    Could someone please help me to verify the following information:
    1]
    We are on SQL server 2012 Enterprise Edition with service pack2 but as per SQL Server 2012 Enterprise Edition under CAL Licensing –We are limited to use 20 logical processors instead 40 logical processors. Our SQL is configured
    on NUMA nodes and with the limitation SQL uses only 2 NUMA nodes on live .There are 10 logical CPUs are evenly assigned to each NUMA nodes. Microsoft recommends that if SQL server configured on NUMA node and we have 2 NUMA nodes, then we may add two data files
    at a time. Please let me know should I add two TempDB data file at a time?
    2] We have TempDB Data and log files both on the same Drive of SQL server  .When I split TempDB into two Data files, I can get them on the same Drive .What your recommendation should I need to create TempDB Data files on the same drive or on separate
    disks?
    3] What would be the blackout plan for splitting the tempdb into multiple files? Please let me know if someone has a better back out plan ?
                1] Run script that create tempdb Database with a single file
    2] Reboot SQL service in order to apply change   
    Your help will be apprecited .
    Thanks ,
    Daizy

    Tom , I am seeing TempDB contention on Production server when there is a heavily load on sql server . We also experiencing the overall system slowness.Please look at Pagelatch wait statistics on our server ,Please advise .
    wait_type
    waiting_tasks_count
    wait_time_ms
    max_wait_time_ms
    signal_wait_time_ms
    PAGELATCH_UP
    2680948
    3609142
    10500
    508214
    PAGELATCH_SH
    1142213
    1338451
    8609
    324538
    PAGELATCH_NL
    0
    0
    0
    0
    PAGELATCH_KP
    0
    0
    0
    0
    PAGELATCH_EX
    44852435
    7798192
    9886
    6108374
    PAGELATCH_DT
    0
    0
    0
    0
    Thanks ,
    Daizy

  • Convert Report6i RDF.file into REP.file

    hi,
    i am using Report 6i and i have made a report according to the user requirement,acctually problem is that i have finanlized the report and paste the copy of RDF.file of such report and paste into the path where the report is "live"(accessible for user) but when i run through the shortcut it run's the old version of the Report.I think the path of live version report the REP.file should be paste but i don't know how to convert RDF.file into REP.file
    Thanks & Regards
    Faizan Khalil

    Faizan,
    its the copy of the post in the forms forum.
    Go to the menu File-->Administration-->Compile Report or use the shortcut key Ctrl + T . then it will ask to generate the REP file. select the path where you want to save the rep file.
    Regards,
    Manu.
    If this answer is helpful or correct, please mark it. Thanks.

  • Converting Report6i rdf.file into rep.file

    hi,
    i am using Report 6i and i have made a report according to the user requirement,acctually problem is that i have finanlized the report and paste the copy of RDF.file of such report and paste into the path where the report is "live"(accessible for user) but when i run through the shortcut it run's the old version of the Report.I think the path of live version report the REP.file should be paste but i don't know how to convert RDF.file into REP.file
    Thanks & Regards
    Faizan Khalil

    Faizan,
    Go to the menu File-->Administration-->Compile Report or use the shortcut key Ctrl + T . then it will ask to generate the REP file. select the path where you want to save the rep file.
    Regards,
    Manu.
    If this answer is helpful or correct, please mark it. Thanks.

  • How to include external .js file into .ear file using NetBean 5.5.1?

    is it possible to include external .js file into .ear file using NetBean 5.5.1? if not, then where should I placed the external .js file and how to write the src="xxx" element? (that is , how to write the path of "xxx"?)
    I am using JBOSS 4.2.2 GA as server
    thx!!

    Even this is also not possible because, the code in that package is developed by DWR and i am just adding it to my lib folder and importing the respective classes. In the same manner i need to include the *.js* file in the JSP.It took me about 3 minutes reading through the [DWR Getting Started|http://getahead.org/dwr/getstarted] page to learn that you don't have to do any of that. Perhaps you should read that page?

  • How To Divide Source File Into Smaller Files Without Exporting?

    Hello Everyone,
    I'm a beginner with PPro CS4 and to video editing in general. I've done a lot of Googling and searching of these forums to get an answer to this question, but I haven't found a clear answer. Here's my problem:
    I have many hours of HDV footage shot over the past few years with a Canon HV30. This footage is on dozens of DV tape cassettes. I want to capture most of it to disk.
    When I capture a tape to disk, I get a single large mpeg4 file. (PPro captures all HDV footage to mpeg4.) "Scene select" doesn't work with the HV30, so my only other way to make smaller capture files would be to set In/Out points with batch capture. But this would mean hours of fast-forwarding and reversing with the VCR-like controls on the camera to review all the tapes and set the points. I thought it might be FASTER to simply capture an entire tape in one operation, THEN review the captured tape within PPro (it's much faster using the scrubber), and dividing that file into smaller files within PPro, thereby avoiding all the mechanical fast-forwarding and rewinding on the camera itself.
    But the only way I can find to do this seems to involve EXPORTING clips. Am I wrong to think that exporting a clip to a new file involves a degradation of the original mpeg4 source file? Or will there be no loss to the quality if I simply export to mpeg4 format?
    It seems there should be an easy way to simply divide the original capture into smaller source files for later editing, without putting the footage through another generation of processing (exporting), which might entail some loss of quality. Or am I wrong about this?
    (CS4 Master Suite, i7 3630k, 16GB RAM, C: 256GB SSD, D: 1T Setpoint F3, E: 1T Setpoint F3)

    HDV footage is mpeg2 (whats in a number ). CS4 does not do scene detect you need to use HDV split for that.
    http://strony.aster.pl/paviko/hdvsplit.htm.
    You can run your already captured files through hdv split and it will chop the file into clips and off you go.

  • How to convert Xls file into Xml file

    Hi,
    I am trying to convert Xls file into Xml  but there  is no any direct procedure for it
    Pls help me out to convert Xls file into Xml file
    Thanks
    Anushree

    you will require to write a module in your file adapter for the same.
    ref: /people/sap.user72/blog/2005/07/04/read-excel-instead-of-xml-through-fileadapter as mentioned in the earlier post.
    Else you can also use Conversion Agent to read the same.
    Ref: http://help.sap.com/saphelp_nw04/helpdata/en/43/4c38c4cf105f85e10000000a1553f6/content.htm

Maybe you are looking for

  • HT201401 Is there a way to fix/override the silent switch on my iphone 4?

    The silent switch on my phone doesn't do anything anymore. Sometimes my phone will vibrate randomly for prolonged periods of time as it switches itself on and off silent mode. Any advice is welcome.

  • F-22,f-43 tables

    Hi all, I need some information regarding “Customer and Vendor Invoices ” 1.     Can any one please help me what are all the tables that update when we post customer and vendor invoice with F-22 and F-43. please give me all relevant information,. I w

  • How do I open Aperture in Yosemite

    I have recently upgraded my OS to Yosemite, and now I can't open Aperture and access any of my photos. What to do?

  • Operation Name part of request XML

    Hi, In weblogic 10.3, We have created a web service from the WSDL. All is OK but the problem that we are facing is that the request XML has the request object encapsulated within the transaction Name tag. For example, if the operation name is getNume

  • MDT 2012 Suspend Task Sequence Problem

    Hi , I have been using LTISuspens.wsf without problem in my MDT 2010 and MDT 2010 U1 for a long time. Recently I have create my test MDT 2012 and I have problem with this task. I have created the new Run Command line cscript.exe "%SCRIPTROOT%\LTISusp