Java FileOutputStream Write saveInputStream(InputStream is, String filePath)

Here you can find the source of saveInputStream(InputStream is, String filePath)

Description

save Input Stream

License

Apache License

Declaration

public static void saveInputStream(InputStream is, String filePath) 

Method Source Code

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

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

public class Main {
    public static void saveInputStream(InputStream is, String filePath) {
        FileOutputStream fos = null;
        try {/*  w  w w.  j  a va 2 s .c  om*/
            fos = new FileOutputStream(filePath);
            byte[] buf = new byte[1024];
            int len;
            while ((len = is.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. saveFileBinary(final File file, final byte[] data)
  2. SaveFileFromInputStream(InputStream in, String fileName, String path)
  3. SaveFileFromInputStream(InputStream stream, String path, String filename)
  4. saveInFile(String filename, String content, String charsetName)
  5. saveInputStream(InputStream _input_stream, File _file)
  6. saveInt16bit(String filename, int[] intData)
  7. saveIntArrayToFile(int[] array, File file)
  8. saveKeyToFile(String key)
  9. saveLongList(String file, Collection c, boolean append)