Here you can find the source of copyFile(File inFile, File outFile)
Parameter | Description |
---|---|
inFile | the file to copy. |
outFile | the copy. |
public static boolean copyFile(File inFile, File outFile)
//package com.java2s; /*--------------------------------------------------------------- * Copyright 2005 by the Radiological Society of North America * * This source software is released under the terms of the * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense) *----------------------------------------------------------------*/ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class Main { /**/*from w w w . ja v a 2 s . c o m*/ * Copies a file. * @param inFile the file to copy. * @param outFile the copy. * @return true if the operation succeeded completely; false otherwise. */ public static boolean copyFile(File inFile, File outFile) { BufferedInputStream in = null; BufferedOutputStream out = null; boolean result = true; try { in = new BufferedInputStream(new FileInputStream(inFile)); out = new BufferedOutputStream(new FileOutputStream(outFile)); byte[] buffer = new byte[4096]; int n; while ((n = in.read(buffer, 0, 4096)) != -1) out.write(buffer, 0, n); } catch (Exception e) { result = false; } finally { try { out.flush(); out.close(); in.close(); } catch (Exception ignore) { } } return result; } }