Java FileOutputStream Write saveStream(InputStream is, File output)

Here you can find the source of saveStream(InputStream is, File output)

Description

save Stream

License

Open Source License

Declaration

public static void saveStream(InputStream is, File output)
            throws IOException 

Method Source Code

//package com.java2s;
/*//from w ww .  j  a  v a  2s . c  o  m
 *  Copyright (C) 2010-2015 JPEXS, All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 */

import java.io.File;

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

public class Main {
    public static void saveStream(InputStream is, File output)
            throws IOException {
        byte[] buf = new byte[1024];
        int cnt;
        try (FileOutputStream fos = new FileOutputStream(output)) {
            while ((cnt = is.read(buf)) > 0) {
                fos.write(buf, 0, cnt);
                fos.flush();
            }
        }
    }
}

Related

  1. saveIntArrayToFile(int[] array, File file)
  2. saveKeyToFile(String key)
  3. saveLongList(String file, Collection c, boolean append)
  4. saveProxyClass(String path, String proxyClassName, Class[] interfaces)
  5. saveResouce(String resourceName, String outputFile)
  6. saveStream(InputStream stream, File targetFile)
  7. saveStreamToFile(InputStream in, File outFile)
  8. saveStreamToFile(InputStream is, File destFile)
  9. saveStringIntoFile(File file, String contents)