Here you can find the source of save(final InputStream in, final File file)
Parameter | Description |
---|---|
in | The InputStream to read from. This stream will not be closed when this method returns. |
file | The file to save to. Will be replaced if it exists, or created if it doesn't. |
Parameter | Description |
---|---|
IOException | an exception |
public final static void save(final InputStream in, final File file) throws IOException
//package com.java2s; /*/* w ww . j av a 2 s .co m*/ * This file is part of Skript. * * Skript is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Skript 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Skript. If not, see <http://www.gnu.org/licenses/>. * * * Copyright 2011-2014 Peter G?ttinger * */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Saves the contents of an InputStream in a file. * * @param in The InputStream to read from. This stream will not be closed when this method returns. * @param file The file to save to. Will be replaced if it exists, or created if it doesn't. * @throws IOException */ public final static void save(final InputStream in, final File file) throws IOException { file.getParentFile().mkdirs(); FileOutputStream out = null; try { out = new FileOutputStream(file); final byte[] buffer = new byte[16 * 1024]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); } } finally { if (out != null) out.close(); } } }