Java FileOutputStream Write saveToFile(InputStream stream, File file)

Here you can find the source of saveToFile(InputStream stream, File file)

Description

save To File

License

Open Source License

Declaration

public static void saveToFile(InputStream stream, File file) throws IOException 

Method Source Code


//package com.java2s;
/*/*from  w  w  w. ja  v a2 s. c  o  m*/
 * beetlejuice
 * beetlejuice-api
 * Copyright (C) 2011-2013 art of coding UG, http://www.art-of-coding.eu/
 *
 * Alle Rechte vorbehalten. Nutzung unterliegt Lizenzbedingungen.
 * All rights reserved. Use is subject to license terms.
 *
 * rbe, 14.01.13 12:59
 */

import java.io.*;

public class Main {
    private static final int BUF_SIZE = 128 * 1024;

    public static void saveToFile(InputStream stream, File file) throws IOException {
        FileOutputStream fos = new FileOutputStream(file);
        byte[] buf = new byte[BUF_SIZE];
        int len;
        while ((len = stream.read(buf)) != -1) {
            fos.write(buf, 0, len);
        }
        fos.close();
    }

    public static void saveToFile(byte[] b, File file) throws IOException {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(b);
        fos.close();
    }
}

Related

  1. saveToFile(File file, byte[] buffer)
  2. saveToFile(final String file, final byte[] data, final boolean overwrite)
  3. saveToFile(final String text, final File file)
  4. saveToFile(InputStream in, File dst)
  5. saveToFile(InputStream in, String fileName)
  6. saveToFile(String baseName, String extension, byte[] content)
  7. saveToFile(String data, File file)
  8. saveToFile(String data, File file)
  9. saveToFile(String fileName, String fileCode, File dir, String fileExtention)