Java FileOutputStream Write saveToFile(InputStream in, String fileName)

Here you can find the source of saveToFile(InputStream in, String fileName)

Description

save To File

License

Apache License

Declaration

public static void saveToFile(InputStream in, String fileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedInputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

    public static void saveToFile(InputStream in, String fileName) throws IOException {
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        int BUFFER_SIZE = 1024;
        byte[] buf = new byte[BUFFER_SIZE];
        int size = 0;
        bis = new BufferedInputStream(in);
        fos = new FileOutputStream(fileName);
        while ((size = bis.read(buf)) != -1)
            fos.write(buf, 0, size);//from ww  w . j  ava 2  s.  co  m
        fos.close();
        bis.close();
    }
}

Related

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