【发布时间】:2013-01-18 08:17:09
【问题描述】:
我有一个要合并的文件数组。这是我尝试过的,但没有成功。
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]);
}
}
【问题讨论】:
-
那么上面的代码有什么问题呢?
-
如果只想解决问题可以使用stackoverflow.com/questions/2477271/… 或者 cat file1 file2 ... filen > concatenated_file
-
@awregan - 他想用 Java 来做...
标签: java