Java: Need to create PDF from byte-Array
One can utilize the autoclosable interface that was introduced in java 7.
try (OutputStream out = new FileOutputStream("out.pdf")) {
out.write(bArray);
}
Sending your output through a FileWriter
is corrupting it because the data is bytes, and FileWriter
s are for writing characters. All you need is:
OutputStream out = new FileOutputStream("out.pdf");
out.write(bArray);
out.close();