Last active
August 29, 2015 14:01
-
-
Save werbet/e2f61ef29eebad7e0d45 to your computer and use it in GitHub Desktop.
How to get a byte array out of a binary file, and copy it into another file, effectively creating a copy of the original file
This file contains 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.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
public class BinaryFileCopy { | |
public static void main(String[] args) throws IOException { | |
File file = new File("/home/eriko/Videos/big_buck_bunny_480p_stereo.ogg"); | |
byte[] fileData = new byte[(int) file.length()]; | |
DataInputStream dis = new DataInputStream(new FileInputStream(file)); | |
dis.readFully(fileData); | |
dis.close(); | |
File outFile = new File("/home/eriko/Videos/copia.ogg"); | |
DataOutputStream dos = new DataOutputStream(new FileOutputStream(outFile)); | |
dos.write(fileData, 0, fileData.length); | |
dos.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment