import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* 将一个文件夹下的所有java文件目录写入到一个文件中
*
* @author hugm 1,通过递归获取所有的文件对象 2,判断如果是文件的话将文件的绝对路径写入到一个文件中
*
*/
public class Recursion {
public static void main(String[] args) throws IOException {
File file = new File("D:\\MySource\\IO");
recursion(file);
}
public static void recursion(File file) throws IOException{
BufferedWriter bw = new BufferedWriter(new FileWriter("path.txt",true));
File[] files = file.listFiles();
for (File file2 : files) {
if(file2.isDirectory()){
recursion(file2);
}else if(file2.isFile()&&file2.getName().endsWith(".java")){
bw.write(file2.getAbsolutePath());
bw.newLine();
bw.flush();
bw.close();
}
}
}
}
下面是问题的信息 弄不明白 头疼死了
at java.io.BufferedWriter.write(BufferedWriter.java:203)
at java.io.Writer.write(Writer.java:140)
at com.hgm.io.Recursion.recursion(Recursion.java:27)
at com.hgm.io.Recursion.recursion(Recursion.java:25)
at com.hgm.io.Recursion.recursion(Recursion.java:25)
at com.hgm.io.Recursion.recursion(Recursion.java:25)
at com.hgm.io.Recursion.recursion(Recursion.java:25)
at com.hgm.io.Recursion.main(Recursion.java:17)
|
|