package edu.jlu.fuliang;
import java.io.*;
public class CopyFiles {
public void copyAllFiles(String dirName, String toFileName) {
if (dirName.length() == 0) {
dirName = new String("..");
}
try {
File path = new File(dirName);
String[] fileNames = path.list();
if (fileNames != null) {
for (int i = 0; i < fileNames.length; i++) {
File file = new File(path.getPath(), fileNames[i]);
if (file.isDirectory()) {
copyAllFiles(file.getAbsolutePath(), toFileName);
} else {
if (fileNames[i].endsWith(".java")) {
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(
toFileName, true);
byte[] buf = new byte[512];
int size = 0;
while ((size = fis.read(buf, 0, buf.length)) != -1) {
fos.write(buf, 0, size);
fos.flush();
}
fis.close();
fos.close();
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CopyFiles copyFiles = new CopyFiles();
copyFiles.copyAllFiles(args[0], args[1]);
}
}