Here you can find the source of copyFile(File inputFile, File outputFile)
Parameter | Description |
---|---|
inputFile | a parameter |
outputFile | will be created if it does not exist |
Parameter | Description |
---|---|
IOException | an exception |
private static void copyFile(File inputFile, File outputFile) throws IOException
//package com.java2s; /****************************************************************************** * Copyright (c) 2008-2013, Linagora/*from ww w .j a v a 2s. c o m*/ * * 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: * Linagora - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copies the content from inputFile into outputFile. * * @param inputFile * @param outputFile will be created if it does not exist * @throws IOException */ private static void copyFile(File inputFile, File outputFile) throws IOException { InputStream is = null; OutputStream os = null; try { is = new FileInputStream(inputFile); if (!outputFile.exists() && !outputFile.createNewFile()) throw new IOException("Failed to create " + outputFile.getAbsolutePath() + "."); os = new FileOutputStream(outputFile); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } } finally { if (os != null) { try { os.close(); } catch (Exception e) { // nothing } } if (is != null) is.close(); } } }