Here you can find the source of copyFile(File copyFrom, File copyTo)
Parameter | Description |
---|---|
copyFrom | a parameter |
copyTo | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File copyFrom, File copyTo) throws IOException
//package com.java2s; //License from project: Open Source License 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 { /**//ww w . j a v a 2s . com * Copy a file to a file location * * @param copyFrom * @param copyTo * @throws IOException */ public static void copyFile(File copyFrom, File copyTo) throws IOException { InputStream from = new FileInputStream(copyFrom); OutputStream to = new FileOutputStream(copyTo); copyStream(from, to); } /** * Copy an input stream to a file location * * @param copyFrom * @param copyTo * @throws IOException */ public static void copyStream(InputStream copyFrom, File copyTo) throws IOException { OutputStream to = new FileOutputStream(copyTo); copyStream(copyFrom, to); } /** * Copy an input stream to an output stream * * @param copyFrom * @param copyTo * @throws IOException */ public static void copyStream(InputStream copyFrom, OutputStream copyTo) throws IOException { byte[] buffer = new byte[1024]; int length; while ((length = copyFrom.read(buffer)) > 0) { copyTo.write(buffer, 0, length); } copyTo.flush(); copyTo.close(); copyFrom.close(); } }