50,523
社区成员
发帖
与我相关
我的任务
分享
@SuppressWarnings("unused")
public void union(String path, String newString) throws Exception {
File file = new File(path);
if (file!=null) {
File list[] = file.listFiles();
File newFile = new File(newString);
if(newFile!=null ){
if (newFile.delete()) {
newFile = new File(newString);
System.out.println("删除源文件成功");
}
}
byte buffer[] = new byte[1024];
int readcount;
if (!newFile.getParentFile().exists())
throw new Exception("你合并的文件夹的不存在...");
FileOutputStream writer = new FileOutputStream(newString);
for (File f : list) {
FileInputStream reader = new FileInputStream(f);
while ((readcount = reader.read(buffer)) != -1) {
writer.write(buffer);
}
System.out.println("count "+f.getName());
reader.close();
}
writer.close();
}else {
throw new Exception("file null");
}
}