Java FileInputStream Read writeFile(File file, byte[] buffer, ZipOutputStream zos)

Here you can find the source of writeFile(File file, byte[] buffer, ZipOutputStream zos)

Description

write File

License

Open Source License

Declaration

private static void writeFile(File file, byte[] buffer, ZipOutputStream zos) 

Method Source Code

//package com.java2s;
/**/*from w w  w. ja  v a2s.co m*/
 * Copyright (c) 2013, Robert Cherry * All rights reserved.
 *
 * This file is part of the Faust Engine.
 *
 * The Faust Engine 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 (at your option) any
 * later version.
 *
 * The Faust Engine 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 Faust Engine. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    private static void writeFile(File file, byte[] buffer, ZipOutputStream zos) {

        try {
            try (FileInputStream fis = new FileInputStream(file)) {
                ZipEntry entry = new ZipEntry(file.getName());

                // Place the entry
                zos.putNextEntry(entry);

                //
                int len;

                // Write to zipped file
                while ((len = fis.read(buffer)) > 0) {
                    zos.write(buffer, 0, len);
                }

                //
                fis.close();
            }
        } catch (IOException ioe) {
            // Throw an error eventually
        }
    }
}

Related

  1. readFileToBytes(File f, int max)
  2. readFileToBytes(String path)
  3. readFileToStr(String fn, String charset)
  4. readFileUTF8(String file)
  5. readFileUTF_8(String filePath)
  6. writeFile(InputStream fileInputStream, OutputStream outputStream)
  7. writeFile(OutputStream os, File f)
  8. writeFile(String path, OutputStream out)
  9. writeFileToOutputStream(File file, OutputStream output)