Here you can find the source of copy(FileInputStream iStream, FileOutputStream oStream)
Parameter | Description |
---|---|
iStream | a parameter |
oStream | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
private static void copy(FileInputStream iStream, FileOutputStream oStream) throws IOException
//package com.java2s; /**//from w w w . j a v a 2s. c o m * Aptana Studio * Copyright (c) 2005-2012 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions). * Please see the license.html included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /** * Special optimized version of copying a {@link FileInputStream} to a {@link FileOutputStream}. Uses * {@link FileChannel#transferTo(long, long, java.nio.channels.WritableByteChannel)}. Closes the streams after * copying. * * @param iStream * @param oStream * @throws IOException */ private static void copy(FileInputStream iStream, FileOutputStream oStream) throws IOException { try { FileChannel inChannel = iStream.getChannel(); FileChannel outChannel = oStream.getChannel(); long fileSize = inChannel.size(); long offs = 0, doneCnt = 0, copyCnt = Math.min(65536, fileSize); do { doneCnt = inChannel.transferTo(offs, copyCnt, outChannel); offs += doneCnt; fileSize -= doneCnt; } while (fileSize > 0); } finally { try { if (iStream != null) { iStream.close(); } } catch (Exception e) { // ignore } try { if (oStream != null) { oStream.close(); } } catch (Exception e) { // ignore } } } }