package cn.itcast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
public class CopyFile2 {
public static void main(String[] args) throws IOException {
File srcFile = new File("E:\\学习1\\新建文件夹" +
"\\day05-函数&数组\\day05_code");
//获取所有的.java文件
File[] array = srcFile.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return new File(dir,name).isFile() && name.endsWith(".java");
}
});
File destFile = new File("e:\\abc");
if(!destFile.exists()){
destFile.mkdir();
}
for (File file : array) {
String name = file.getName();
String newname = name.replace(".java", ".jad");
File newfile = new File(destFile,newname);
BufferedReader br = new BufferedReader(new FileReader(file));
BufferedWriter bw = new BufferedWriter(new FileWriter(newfile));
String line = null;
while((line = br.readLine())!= null){
bw.write(line);
bw.newLine();
bw.flush();
}
bw.close();
br.close();
}
}
}
|