package com.aastocks.tradeGateway.io; import java.io.*; public class FileCopier { /* Copy a single file or copy all files from a source directory to a destination directory. */ public static void copy(File src, File dest) throws IOException { if (src.isDirectory()) { dest.mkdirs(); String list[] = src.list(); for (int i = 0; i < list.length; i++) { String dest1 = dest.getPath() + File.separator + list[i]; String src1 = src.getPath() + File.separator + list[i]; copy(new File(src1), new File(dest1)); } } else { FileInputStream fin = new FileInputStream(src); FileOutputStream fout = new FileOutputStream(dest); StreamCopier.copy(fin, fout); fin.close(); fout.close(); } } } class StreamCopier { public static void copy(InputStream in, OutputStream out) throws IOException { synchronized (in) { synchronized (out) { byte[] buffer = new byte[256]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) break; out.write(buffer, 0, bytesRead); } } } } }
FileCopier
最新推荐文章于 2024-08-15 14:47:41 发布