public static void main(String[] args) throws Exception {
File java = new File("E:\\1");
File txt = new File("E:\\2");
File[] arr = java.listFiles();
byte[] by = new byte[1024 * 8];
int len;
for (File file : arr) {
if (file.isFile() && file.getName().endsWith(".java")) {
FileInputStream fi = new FileInputStream(file);
String oname = file.getName();
String xname = oname.substring(0, oname.length() - 4) + ".txt";
FileOutputStream fo = new FileOutputStream(txt + "\\" + xname);
while ((len = fi.read(by)) != -1) {
fo.write(by, 0, len);
}
fi.close();
fo.close();
}
}
} |
|