Skip to content

Instantly share code, notes, and snippets.

@jbrown17
Created September 22, 2015 00:08
Show Gist options
  • Save jbrown17/8527682281db499048f6 to your computer and use it in GitHub Desktop.
Save jbrown17/8527682281db499048f6 to your computer and use it in GitHub Desktop.
Example of FileInput/OutputStream to copy a file
import java.io.*;
public class copyFile {
public static void main(String[] args) {
copyFile(args[0], args[1]);
}
public static void copyFile(String file, String target) {
try {
byte[] buffer = new byte[1024];
InputStream source = new FileInputStream(file);
int byteSize = source.read(buffer);
OutputStream destination = new FileOutputStream(target);
while (byteSize != -1) {
destination.write(buffer);
byteSize = source.read(buffer);
}
} catch (IOException e) {
System.out.println("There was an issue copying the file. Check file names");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment