private static void copyfile(String str,String str1) throws FileNotFoundException {
try {
File file=new File(str);
InputStream is=null;
OutputStream os=null;
byte[] b;
File f=new File(str1);
if(!file.isDirectory()) {
is=new FileInputStream(str);
b=new byte[is.available()];
is.read(b);
os=new FileOutputStream(str1);
os.write(b);
is.close();
os.close();
return;
} else if(!f.exists())
f.mkdirs();
File[] filename=file.listFiles();
for(int i=0;i<filename.length;i++) {
copyfile(filename[i].getAbsolutePath(),str1+"/"+filename[i].getName());
}
} catch(IOException ex) {
filecopycount++;
System.out.println("filecopycount:"+String.valueOf(filecopycount));
if(filecopycount<=5)
copyfile(str,str1);
System.err.println("err:"+ex.toString());
}
}
如果路径不存在就用mkdir建立目录
try {
File file=new File(str);
InputStream is=null;
OutputStream os=null;
byte[] b;
File f=new File(str1);
if(!file.isDirectory()) {
is=new FileInputStream(str);
b=new byte[is.available()];
is.read(b);
os=new FileOutputStream(str1);
os.write(b);
is.close();
os.close();
return;
} else if(!f.exists())
f.mkdirs();
File[] filename=file.listFiles();
for(int i=0;i<filename.length;i++) {
copyfile(filename[i].getAbsolutePath(),str1+"/"+filename[i].getName());
}
} catch(IOException ex) {
filecopycount++;
System.out.println("filecopycount:"+String.valueOf(filecopycount));
if(filecopycount<=5)
copyfile(str,str1);
System.err.println("err:"+ex.toString());
}
}
如果路径不存在就用mkdir建立目录
Runtime.getRuntime().exec("cmd.exe/c copy c:\\temp\\src.jar d:\\temp");
我说的是压缩文件包啊,比如.WAR文件,读字节的办法不行的!