我写了个application的,把c:\的文件拷到d:\temp里,你看看
import java.io.*;public class Application3 {
boolean packFrame = false; public Application3() {
copyDir(new File("c:/"),new File("d:/temp/"));
System.out.println(new File("d:/temp/").getPath()+File.separator);
} public void copyDir(File src_path,File dest_path){
File[] files = src_path.listFiles();
for(int i=0;i<files.length;i++){
File src=files[i];
File dest=new File(dest_path.getPath()+File.separator+files[i].getName());
if(!src.isDirectory())
copyFile(src,dest);
}
} public void copyFile(File src,File dest){
try{
System.out.println(src.getAbsoluteFile()+" -> "+dest.getAbsoluteFile());
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length = -1;
while((length=in.read(buffer))!=-1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();
System.out.println("文件复制成功!");
}catch(Exception e){
System.out.println("文件复制失败!");
}
}
public static void main(String[] args) {
new Application3();
}
}
import java.io.*;public class Application3 {
boolean packFrame = false; public Application3() {
copyDir(new File("c:/"),new File("d:/temp/"));
System.out.println(new File("d:/temp/").getPath()+File.separator);
} public void copyDir(File src_path,File dest_path){
File[] files = src_path.listFiles();
for(int i=0;i<files.length;i++){
File src=files[i];
File dest=new File(dest_path.getPath()+File.separator+files[i].getName());
if(!src.isDirectory())
copyFile(src,dest);
}
} public void copyFile(File src,File dest){
try{
System.out.println(src.getAbsoluteFile()+" -> "+dest.getAbsoluteFile());
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length = -1;
while((length=in.read(buffer))!=-1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();
System.out.println("文件复制成功!");
}catch(Exception e){
System.out.println("文件复制失败!");
}
}
public static void main(String[] args) {
new Application3();
}
}
解决方案 »
- 为什么quartz中CronTriggerBean的cronExpression设置不能再次按某天8点执行呢?
- 关于将岗位关系图以图形化显示的问题
- 怎样得到用户的真实IP?
- cxf2.4.1 spring3.0 rest格式 身份验证 客户端调用 java
- 如何实现网站短信验证,实现手机号验证
- 问一个初级问题(javac SomeServlet,找不到javax.servlet.*; )?
- 急招项目经理
- 急问!快来看看!
- javabean的疑难
- openfire4.3.2源码导入到eclipse中maven install时报错
- 求一本JSP的好书!
- 为什么我的micromedia dreamweaver mx 不能出自动提示?
import java.io.*;public class Application3 {
boolean packFrame = false; public Application3() {
copyDir(new File("c:/temp/"),new File("d:/temp/"));
} public void copyDir(File src_path,File dest_path){
if(!dest_path.exists())
dest_path.mkdirs();
File[] files = src_path.listFiles();
for(int i=0;i<files.length;i++){
File src=files[i];
File dest=new File(dest_path.getPath()+File.separator+files[i].getName());
if(!src.isDirectory())
copyFile(src,dest);
else
copyDir(src,dest);
}
} public void copyFile(File src,File dest){
try{
System.out.println(src.getAbsoluteFile()+" -> "+dest.getAbsoluteFile());
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length = -1;
while((length=in.read(buffer))!=-1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();
System.out.println("文件复制成功!");
}catch(Exception e){
System.out.println("文件复制失败!");
}
} public static void main(String[] args) {
new Application3();
}
}