Reputation: 65
How to save byte array into an binary file in java. I have tries using file writer,bufferedOutputstream but with no results. The data gets saved in the binary file, when the file is opened with notepad, it looks like binary file has been created but when opened with wordpad the actual data appears.
Upvotes: 0
Views: 13969
Reputation: 13061
You can save byte array in this way:
FileOutputStream fos = new FileOutputStream(strFilePath);
String strContent = "Content";
/*
* To write byte array to a file, use
* void write(byte[] bArray) method of Java FileOutputStream class.
*
* This method writes given byte array to a file.
*/
fos.write(strContent.getBytes());
/*
* Close FileOutputStream using,
* void close() method of Java FileOutputStream class.
*
*/
fos.close();
It will create a file with your byte array
Upvotes: 3