Created
November 8, 2019 12:41
-
-
Save seunggabi/1004423b90cfbf069bde483af097e2e9 to your computer and use it in GitHub Desktop.
FileUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
reference