Here you can find the source of copyFile(File src, String target)
Parameter | Description |
---|---|
src | the source File object; |
target | the target file path; |
Parameter | Description |
---|
public static void copyFile(File src, String target) throws FileNotFoundException, IOException
//package com.java2s; import java.io.*; public class Main { /**//from www .j av a 2s . com * copy a file object; * * @param src the source File object; * @param target the target file path; * @throws java.io.FileNotFoundException if the source file not found; * @throws java.io.IOException */ public static void copyFile(File src, String target) throws FileNotFoundException, IOException { int read = 0; byte[] bytes = new byte[4096]; BufferedInputStream in = new BufferedInputStream(new FileInputStream(src)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(target))); while ((read = in.read(bytes)) >= 0) { out.write(bytes, 0, read); } in.close(); out.flush(); out.close(); } /** * copy a file from one path to another; * * @param src the source file path; * @param target the target file path; * @throws FileNotFoundException if the source file not found; * @throws IOException */ public static void copyFile(String src, String target) throws FileNotFoundException, IOException { int read = 0; byte[] bytes = new byte[4096]; BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(src))); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(target))); while ((read = in.read(bytes)) >= 0) { out.write(bytes, 0, read); } in.close(); out.flush(); out.close(); } }