2013-02-03 48 views
-2

可能重複:
merging file in java在java中合併文件

我有,我想在一個文件中合併它們的文件的數組。我用這個,但這不起作用

public static void joinf(File f1, File f2){ 

    try{ 

     InputStream in = new FileInputStream(f1); 


     OutputStream out = new FileOutputStream(f2,true); 

     byte[] buf = new byte[8192]; 
     int len; 
     while ((len = in.read(buf)) > 0){ 
      out.write(buf, 0, len); 
     } 
     in.close(); 
     out.close(); 
     System.out.println("File copied."); 
    } 
    catch(FileNotFoundException ex){ 
     System.out.println(ex.getMessage() + " in the specified directory."); 
     System.exit(0); 
    } 
    catch(IOException e){ 
     System.out.println(e.getMessage());    
    } 
} 


public void pro(File a,File[]b){ 
    for(int i=0;i<b.length;i++){ 


     joinf(a,b[i]); 
    } 
+0

http://stackoverflow.com/questions/14673063/merging-file-in-java – isvforall

+1

請不要發佈[相同的問題](http://stackoverflow.com/q/14673063/335858)。 – dasblinkenlight

+0

,因爲我沒有得到答案,所以我不得不分享它 – user1781384

回答

0

使用:的

joinf(b[i],a); 

代替

joinf(a,b[i]);