Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Created November 8, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seunggabi/1004423b90cfbf069bde483af097e2e9 to your computer and use it in GitHub Desktop.
Save seunggabi/1004423b90cfbf069bde483af097e2e9 to your computer and use it in GitHub Desktop.
FileUtils.java
public class FileUtils {
public static void joinFiles(File destination, File[] sources) throws IOException {
OutputStream output = null;
try {
output = createAppendableStream(destination);
for (File source : sources) {
appendFile(output, source);
}
} finally {
IOUtils.closeQuietly(output);
}
}
private static BufferedOutputStream createAppendableStream(File destination) throws FileNotFoundException {
return new BufferedOutputStream(new FileOutputStream(destination, true));
}
private static void appendFile(OutputStream output, File source) throws IOException {
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(source));
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment