黑马程序员_day24_File类、过滤器和递归、properties类 (三)

2014-11-24 11:39:21 · 作者: · 浏览: 19
list);

}else{

if(filter.accept(dir, file.getName())){//使用过滤器对指定的目的和文件名进行过滤。符合条件进行存储。

list.add(file);

}

}

}

}

}

对集合中存储的内容的信息写入到文件中。

public static void write2File(List list,File dest) throws IOException{

BufferedWriter bufw = null;

try {

bufw = new BufferedWriter(new FileWriter(dest));


//遍历集合。

for (File file : list) {

bufw.write(list.getAbsolutePath());

bufw.newLine();

bufw.flush();

}

} finally{

if(bufw!=null)

try {

bufw.close();

} catch (IOException e) {

throw new RuntimeException("关闭失败");

}

}