0

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.

3
  • 2
    Please send your code. And would you please add some punctuation signs? You know, dots, comas etc... These little signs could help to understand what do you mean. Commented Sep 20, 2012 at 6:31
  • 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. All files are binary, you know? Its just how you interpret those bytes. Commented Sep 20, 2012 at 6:35
  • Please post an SSCCE to illustrate what you have tried. Commented Sep 21, 2012 at 0:19

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.