小编use*_*384的帖子

合并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]);
    }
}
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1