Here you can find the source of copyFiles(File src, File dst)
Parameter | Description |
---|---|
src | a parameter |
dst | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFiles(File src, File dst) throws IOException
import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.text.DecimalFormat; import java.util.Properties; public class Main{ /**//w w w.jav a 2s.co m * copy files from src to dst * @param src * @param dst * @throws IOException */ public static void copyFiles(File src, File dst) throws IOException { if (!src.exists()) return; else if (src.isDirectory() && !dst.isFile()) { if (dst.exists() || dst.mkdirs()) { File[] subSrcs = src.listFiles(); for (File subSrc : subSrcs) { File subDst = new File(dst.getPath() + File.separator + subSrc.getName()); copyFiles(subSrc, subDst); } } } else if (src.isFile() && !dst.isDirectory()) { if (dst.exists() || (dst = createNewFile(dst.getPath())) != null) StreamUtil.copyThenClose(new FileInputStream(src), new FileOutputStream(dst)); } else return; } public static File createNewFile(String filepath) throws IOException { return createNewFile(new File(filepath)); } /** * create a new blank file * @param file * @return * @throws IOException */ public static File createNewFile(File file) throws IOException { File pareFile = file.getParentFile(); if (pareFile.exists() || pareFile.mkdirs()) { File newFile = file; if (newFile.exists() || newFile.createNewFile()) return newFile; } return null; } }