Here you can find the source of copyFileContents(File fromFile, File destination, boolean useTempFilenames)
Parameter | Description |
---|---|
fromFile | a parameter |
destination | a parameter |
useTempFilenames | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
private static File copyFileContents(File fromFile, File destination, boolean useTempFilenames) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2011 Red Hat Inc. 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 ww w. j a v a2s .c o m * Red Hat Inc. - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Prefix for temporary directories created by EFP tests. */ private static final String TMP_DIRECTORY_PREFIX = "eclipse-fedorapackager-tests-temp"; /** * Copy a file into destination {@code destination}. If {@code useTempFile} * is set to true, the a random temporary file in destination will get * created. Otherwise the filename of {@code fromFile} will be used. * * @param fromFile * @param destination * @param useTempFilenames * @return * @throws IOException */ private static File copyFileContents(File fromFile, File destination, boolean useTempFilenames) throws IOException { FileInputStream from = null; FileOutputStream to = null; File toFile = null; if (useTempFilenames) { toFile = File.createTempFile(TMP_DIRECTORY_PREFIX, "", destination); } else { toFile = new File(destination.getAbsolutePath() + File.separatorChar + fromFile.getName()); } try { from = new FileInputStream(fromFile); to = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) { to.write(buffer, 0, bytesRead); // write } } finally { if (from != null) { try { from.close(); } catch (IOException e) { // ignore } } if (to != null) { try { to.close(); } catch (IOException e) { // ignore } } } return toFile; } }