急求:JAVA编写复制文件夹的代码

来源:百度知道 编辑:UC知道 时间:2024/06/25 17:58:20
JAVA编写程序实现复制文件夹的功能,最好用流编写, 变成高人帮帮忙!!!万分感谢!!我急需啊!!

一个简单的方式就是调用cmd命令,使用windows自带的功能来替你完成这个功能
我给你写个例子
import java.io.*;
public class test{
public static void main(String[] args){
BufferedReader in = null;
try{
// 这里你就当作操作对dos一样好了 不过cmd /c 一定不要动
Process pro = Runtime.getRuntime().exec("cmd /c copy d:\\ReadMe.txt e:\\");
in = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String str;
while((str = in.readLine()) != null){
System.out.println(str);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(in != null){
try{
in.close();
}catch(IOException i){
i.printStackTrace();
}
}
}
}
}