- import java.io.*;
- public class Demo11 {
- static String sourcePath = "D:\\";
- static String aimPath = "E:\\hahaha";
- public static void main(String[] args)throws Exception{
- File file = new File(sourcePath);
- listFile(file);
- }
- private static void listFile(File file)throws Exception{
-
- File[] files = file.listFiles();
- for(int x = 0;x<files.length;x++){
- if(files[x].isDirectory())
- listFile(files[x]);
- if(files[x].getName().endsWith(".java"))
- copy(files[x]);
- }
- }
- private static void copy(File file)throws Exception{
- String pathf =file.getPath();
- String paths = pathf.replace(sourcePath, "");
- String path = paths.replace(".java", ".txt");
- FileInputStream fis = new FileInputStream(pathf);
- FileOutputStream fos = new FileOutputStream(aimPath+File.separator+path);
-
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = fis.read(buf))!=-1){
- fos.write(buf,0,len);
- }
- fis.close();
- fos.close();
- }
- }
复制代码 |
|