Here you can find the source of copyStream(InputStream in, File dest)
Parameter | Description |
---|---|
in | the input stream. |
dest | the destination. |
true
if the file was successfully copied, false
otherwise.
public static boolean copyStream(InputStream in, File dest)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . j a va 2s.c o m * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copy a file content to another location. * * @param in the input stream. * @param dest the destination. * @return <code>true</code> if the file was successfully copied, * <code>false</code> otherwise. */ public static boolean copyStream(InputStream in, File dest) { try { OutputStream out = new FileOutputStream(dest); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; } }