public class FileOutputStreamTest {
public static void main(String[] args) throws IOException {
Filedir = new File("d:/test");
FileOutputStreamfos = new FileOutputStream("d:/文件清单.txt");
getListFile(dir,fos);
fos.close();
}
//获取指定目录下的文件清单
public static void getListFile(File dir ,FileOutputStream fos) throws IOException {
File[]files = dir.listFiles( new FileFilter(){
public boolean accept(File pathname) {
return (pathname.isDirectory()) ||
(pathname.isFile() && pathname.getName().endsWith(".java"));
}
});
//判断
if( files != null ){
for (File file : files) {
if( file.isDirectory() ){
getListFile(file,fos);
}else{
//一定是文件
System.out.println(file);
Stringpath = file.getAbsolutePath() +System.getProperty("line.separator");
fos.write(path.getBytes());
}
}
}
}
}