public static boolean copyFolder(String srcdir,String destdir)
{
if(srcdir==null || srcdir.length()==0)
return false;
File srcf = new File(srcdir);
File destf = new File(destdir); if(srcf.isDirectory() || destf.isDirectory()) return false;
if(!srcf.exists()) return false;
File destD = new File(destf.getParent());
if(!destD.exists())
if(!destD.mkdirs())
return false;
int read = 1;
try
{
FileInputStream fis = new FileInputStream(srcdir);
FileOutputStream fos = new FileOutputStream(destdir);
while(read > 0)
{
byte[] b = new byte[1024];
read = fis.read(b,0,1024);
if(read > 0)
fos.write(b, 0, read);
}
}
catch(IOException ioe)
{
System.err.println(ioe.toString());
return false;
}
return true;
}
{
if(srcdir==null || srcdir.length()==0)
return false;
File srcf = new File(srcdir);
File destf = new File(destdir); if(srcf.isDirectory() || destf.isDirectory()) return false;
if(!srcf.exists()) return false;
File destD = new File(destf.getParent());
if(!destD.exists())
if(!destD.mkdirs())
return false;
int read = 1;
try
{
FileInputStream fis = new FileInputStream(srcdir);
FileOutputStream fos = new FileOutputStream(destdir);
while(read > 0)
{
byte[] b = new byte[1024];
read = fis.read(b,0,1024);
if(read > 0)
fos.write(b, 0, read);
}
}
catch(IOException ioe)
{
System.err.println(ioe.toString());
return false;
}
return true;
}
解决方案 »
- 选用什么MVC
- 关于JEditorPane
- 再STRUTS 中图片上传
- 找个上海程序员QQ群?
- hibernate出错,Exception in thread "main" org.hibernate.MappingException: Unknown entity: dd.Person
- 使用Jbuilder 2006和Weblogic, Oracle开发session bean的时候,有关datasource的jndi在xml配置文件中的信息能不能能通过Jbuilder自动声称
- 页面出现乱码我该如何处理?谢谢了!如例:
- TRANSACTION应该加入哪个包啊
- 请大家帮助优化一下RESIN.conf的参数配置
- resin连接池奇怪的问题
- 我的EJB问题?请帮忙
- WEBLOGIC新手:如何设置连接池中的URL,NAME,DRIVER Classname之类的属性
byte[] b = new byte[1024];
read = fis.read(b,0,1024);
if(read > 0)
fos.write(b, 0, read);
public class testCopy
{
public static boolean copyFolder(String srcdir,String destdir)
{
File srcf = new File(srcdir);
File destf = new File(destdir);
if(destf.exists()){
System.out.println("Destination file is already exist!");
return false;
}
if(srcf.exists()){
if(srcf.isDirectory()){
destf.mkdirs();
String[] files=srcf.list();
for(int i=0;i<files.length;i++){
if(!(files[i].equals(".")||files[i].equals("..")))
copyFolder(srcdir+"\\"+files[i],destdir+"\\"+files[i]);
}
}else{
try{
FileInputStream fis = new FileInputStream(srcdir);
FileOutputStream fos = new FileOutputStream(destdir);
byte[] b = new byte[1024];
int read=1;
while(read > 0)
{
read = fis.read(b,0,1024);
if(read > 0)
fos.write(b, 0, read);
}
}
catch(IOException ioe){
ioe.printStackTrace();
return false;
}
}
}
return true;
}
public static void main(String args[]){
if(args.length!=2){
System.out.println("Please enter the source folder name and destination name!");
}else
copyFolder(args[0],args[1]);
}
}