In this section, you will learn how to reads the entire content of a file into a byte array.
In this section, you will learn how to reads the entire content of a file into a byte array.In this section, you will learn how to reads the entire content of a file into a byte array.
Description of code:
We have created an instance of InputStream class that takes the file. The byte array hold the data of the file and the read() method of InputStream class read the whole file data into an array of bytes.
read() method- This method of InputStream class reads up to the length of bytes from the input stream into an array of bytes.
Here is the code:
import java.io.*;
|
Above code will file into a byte array.
Then the bye array is converted to String using following code:
String s = new String(bytes);
System.out.println(s);
and printed on the System console.