Here you can find the source of copyFile(final File source, final File dest)
Parameter | Description |
---|---|
source | source. |
dest | destination. |
Parameter | Description |
---|
public static void copyFile(final File source, final File dest) throws IOException
//package com.java2s; /**/*from w w w .j a v a 2s .co m*/ * Copyright (c) {2011} {meter@rbtsb.com} { * individual contributors as indicated by the @authors tag}. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Private License v1.0 * which accompanies this distribution, and is available at * http://www.rbtsb.com */ 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 { /** * @param source * source. * @param dest * destination. * @throws Exception . */ public static void copyFile(final File source, final File dest) throws IOException { if (!dest.getParentFile().exists()) { String dir = dest.getParentFile().toString(); new File(dir).mkdir(); } InputStream in = null; OutputStream out = null; if (source.exists()) { try { in = new FileInputStream(source); out = new FileOutputStream(dest); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { if (in != null) in.close(); if (out != null) out.close(); } } } }