Java FileOutputStream Write saveToDisk(InputStream is, String filename)

Here you can find the source of saveToDisk(InputStream is, String filename)

Description

save primary conetent to local

License

Open Source License

Parameter

Parameter Description
is a parameter
filename a parameter

Exception

Parameter Description
FileNotFoundException an exception
IOException an exception

Declaration

public static void saveToDisk(InputStream is, String filename)
        throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/* bcwti/*w  w w.j a v a 2s.co  m*/
 *
 * Copyright (c) 2011 Parametric Technology Corporation (PTC). All Rights
 * Reserved.
 *
 * This software is the confidential and proprietary information of PTC
 * and is subject to the terms of a software license agreement. You shall
 * not disclose such confidential information and shall use it only in accordance
 * with the terms of the license agreement.
 *
 * ecwti
 */

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

public class Main {
    /**
     * save primary conetent to local
     * @param is
     * @param filename
     * @throws FileNotFoundException
     * @throws IOException
     */
    public static void saveToDisk(InputStream is, String filename)
            throws FileNotFoundException, IOException {
        FileOutputStream fos = new FileOutputStream(filename);
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = is.read(buf)) > 0) {
            fos.write(buf, 0, len);
        }
        fos.flush();
        fos.close();
    }
}

Related

  1. saveTo(InputStream in, String fileName)
  2. saveTo(String path, InputStream in)
  3. saveTo(String path, InputStream in)
  4. saveToBinaryFile(File dest, byte[] data)
  5. saveToDisc(final InputStream fileInputStream, final String fileUploadPath)
  6. saveToDisk(String contents, String filename)
  7. saveToEml(Message mail, File emlFile)
  8. saveToFile(byte[] data, String filename)
  9. saveToFile(File file, byte[] buffer)