Friday, June 24, 2011

Java: read data as byte array from file

Share at Facebook

Using the FileInputStream of java, you can read data from a file into a byte array. Below is the sample code that will fill the byte array from the provided file.

String fileName = "test.txt";
File file = new File(fileName);
FileInputStream fin = new FileInputStream(file);
byte byteArray[] = new byte[(int)file.length()];;

No comments: