How to convert byte[] to blob in Java

In this article, you will see how convert byte[] to blob and vice versa in Java.

File resume = new File("C:\\Resume.doc");
byte[] fileContent = new byte[(int) resume.length()];
try {
    FileInputStream fileInputStream = new FileInputStream(resume);
} catch (Exception e) {
Blob blob = Hibernate.createBlob(fileContent);

How to convert a Blob into a byte array

byte[] blobAsBytes = blob.getBytes(1, (int)blob.length());


One Response to How to convert byte[] to blob in Java

  1. Nadeeshan jayawardana December 15, 2013 at 10:57 am #

    my error is “ error: cannot find symbol of Blob”. did i want to import any libraries into my class??????

Leave a Reply