import java.io.*; public class DirectoryCopy{ public static void main(String[] args)throws Exception{ File f = new File("E:\\tool\\java\\j2se1.5\\docs"); if(f.isDirectory()){ String str = "F:\\upload\\" ; File d = new File(str); d.mkdir(); copy(f,str); } } public static void copy(File f,String str)throws Exception{ File[] fs = f.listFiles(); FileInputStream in ; FileOutputStream out; for(int i=0 ; i<fs.length; i++){ if(fs[i].isDirectory()) { File file = new File(str+fs[i].getName()); file.mkdir(); copy(fs[i],str+fs[i].getName()+"\\"); } in = new FileInputStream(fs[i]); out= new FileOutputStream(str+fs[i].getName()); byte[] context = new byte[1024] ; int length; while((length=in.read(context))!=-1){ out.write(context,0,length); out.flush(); } out.close(); in.close(); } } }
?