Here you can find the source of saveByteArrayToFile(byte[] content, Path targetPath)
public static void saveByteArrayToFile(byte[] content, Path targetPath) throws IOException
//package com.java2s; /*//from w w w .j a v a 2 s . co m ?Developed with the contribution of the European Commission - Directorate General for Maritime Affairs and Fisheries ? European Union, 2015-2016. This file is part of the Integrated Fisheries Data Management (IFDM) Suite. The IFDM Suite is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. The IFDM Suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the IFDM Suite. If not, see <http://www.gnu.org/licenses/>. */ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; public class Main { public static void saveByteArrayToFile(byte[] content, Path targetPath) throws IOException { File file = targetPath.toFile(); if (!file.exists()) { file.createNewFile(); } FileOutputStream fop = new FileOutputStream(file); InputStream is = new ByteArrayInputStream(content); byte[] buf = new byte[4096]; int bytesRead; while ((bytesRead = is.read(buf)) != -1) { fop.write(buf, 0, bytesRead); } fop.close(); } }