黑马程序员技术交流社区
标题:
求指导。
[打印本页]
作者:
天蝎降降温
时间:
2014-10-20 12:14
标题:
求指导。
public class Test7 {
public static void main(String[] args) throws IOException {
String s1 = "c://1";
String s2 = "d://1";
copyF(s1,s2);
}
public static void copyF(String oldpath,String newpath) throws IOException{
File f1 = new File(newpath);
if(!f1.exists())
{
f1.mkdirs();
}
File f2 = new File(oldpath);
File[] fi = f2.listFiles();
//File temp = null;
for(File f: fi){
if(f.isDirectory()){
File f3 = new File(f1,f.getName());
f3.mkdirs();
copyF(f.getAbsolutePath(),f3.getAbsolutePath());
//temp = new File(oldpath+File.separator+f.getName());
// f1 = new File(temp.getName());
// copyF(temp.getAbsolutePath(),f1.getAbsolutePath());
}
if(f.isFile()){
BufferedInputStream bi =new BufferedInputStream
(new FileInputStream(f));
BufferedOutputStream bo = new BufferedOutputStream
(new FileOutputStream(f1.getAbsolutePath()+File.separator+f.getName()));
int i =0;
while((i=bi.read())!=-1){
bo.write(i);
bo.flush();
}
bi.close();
bo.close();
}
}
}
}
复制代码
我这个复制多级文件夹有什么需要改进的地方,成是成功了,但我发现有点点别扭。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2