文件自我疯狂复制

package com.hfjh.common;
import java.io.*;

public class CopyFile {
    public void copy(String s) {
  try{
	  s=s+"\\CopyFile.java";
     FileInputStream input=new FileInputStream("src\\com\\hfjh\\common\\CopyFile.java");//可替换为任何路径何和文件名
     FileOutputStream output=new FileOutputStream(s);//可替换为任何路径何和文件名     
     int in=input.read();
     while(in!=-1){
  output.write(in);
  in=input.read();
     }
 }catch (IOException e){
     System.out.println(e.toString());
 }
    }
}
package com.hfjh.common;

import java.io.File;

public class TraverseFolder {
	static void ListFilesInDirectory(String path ) {
		 File file = new File(path);
		 CopyFile cf = new CopyFile();
		 String s = new String();
		 File[] files = file.listFiles();
		 for (File fl : files) {
		     if (fl.isDirectory())
		  {ListFilesInDirectory(fl.toString());
		  s=file.getPath();
		  cf.copy(s);
		   }  
		     else{
		  System.out.println(fl.getName());
		  s=file.getPath();
		  cf.copy(s);
		  }
		 }
		    }
	public static void main(String args[]){
	   TraverseFolder.ListFilesInDirectory("WEBsearch");	
	}
}


你可能感兴趣的:(String,File,Class,input,Path,output)