Sep
23
|
Use the File classes length() method to determine the size of the file and thus the required size for the byte array. You can then use the readFully() method in DataOutputStream to read the file into the byte array.
File file = new File("myfile.dat"); // determine amount of bytes needed byte[] content = new byte[(int)file.length()]; // Create input stream to read file DataInputStream in = new DataInputStream( new FileInputStream(file))); // Read contents of file into byte array in.readFully(content); in.close();
Leave a Reply
You must be logged in to post a comment.