1try (FileOutputStream fos = new FileOutputStream("pathname")) {
2 fos.write(myByteArray);
3 //fos.close(); There is no more need for this line since you had created the instance of "fos" inside the try. And this will automatically close the OutputStream
4}