Created
September 22, 2015 00:08
-
-
Save jbrown17/8527682281db499048f6 to your computer and use it in GitHub Desktop.
Example of FileInput/OutputStream to copy a file
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
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