import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
File srcForder = new File("d:\\");
File destForder = new File("d:\\Test\\");
isFile(srcForder, destForder);
}
private static void isFile(File srcForder, File destForder) throws IOException {
if (!destForder.exists())
destForder.mkdir();
File[] file = srcForder.listFiles();
if (file != null) {
for (File srcFile : file) {
if (srcFile.isDirectory()) {
isFile(srcFile, destForder);
} else {
if (srcFile.getName().endsWith(".java")) {
File destFile = new File (destForder,srcFile.getName()) ;
copyFile(srcFile, destFile);
}
}
}
}
}
private static void copyFile(File srcFile, File destFile) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(srcFile));
BufferedWriter bw = new BufferedWriter(new FileWriter(destFile)) ;
String line = null ;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
bw.flush();
}
br.close();
bw.close();
}
}