Java FileOutputStream Write saveToFile(String filePath, InputStream in)

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

Description

save To File

License

Apache License

Declaration

private static void saveToFile(String filePath, InputStream in) 

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 {
    private static void saveToFile(String filePath, InputStream in) {
        FileOutputStream fos = null;
        BufferedInputStream bis = null;

        try {//from  ww w.  j  av  a2s .c  o  m
            int BUFFER_SIZE = 1024;
            byte[] buf = new byte[BUFFER_SIZE];
            int size = 0;

            bis = new BufferedInputStream(in);

            fos = new FileOutputStream(filePath);

            while ((size = bis.read(buf)) != -1)
                fos.write(buf, 0, size);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. saveToFile(InputStream stream, File file)
  2. saveToFile(String baseName, String extension, byte[] content)
  3. saveToFile(String data, File file)
  4. saveToFile(String data, File file)
  5. saveToFile(String fileName, String fileCode, File dir, String fileExtention)
  6. saveToTextFile(String filename, byte[] text)
  7. SaveToZipSB(File file, String ZippedFile, StringBuilder sb)
  8. saveZip(String fileName, Map dataMap)
  9. saveZipFile(String zipFileName, File toBeZipped)