Here you can find the source of copyFile(File in, File out)
Parameter | Description |
---|---|
in | source |
out | target |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File in, File out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /**/*from www. j av a 2 s. c om*/ * Copies a file from one location to antother * * @param in source * @param out target * @throws IOException */ public static void copyFile(File in, File out) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream(in); copyStreamToFile(fis, out); } finally { if (fis != null) { fis.close(); } } } public static void copyStreamToFile(InputStream in, File out) throws IOException { FileOutputStream fos = null; try { fos = new FileOutputStream(out); byte[] buf = new byte[1024]; int i = 0; while ((i = in.read(buf)) != -1) { fos.write(buf, 0, i); } } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } }