In this program we will read a file in the form of a byte array. We can do it very easily. Firstly we will create an object of File class and pass the name of the file which we want to read, in the constructor of File class. We will use DataInputStream to read primitive data types.
We are using the following methods:
length(): It gives the length of the file.
Getting the file size code: ReadInByteArray.java
import java.io.*;
|
The following code helps you in getting the file size in byte array.
Here is the Byte Array code: ByteArrayExample.java
import java.io.*;
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Reading a File into a Byte Array View All Comments
Post your Comment