遍历给定目录并将特定文件的名字写入文件

来源:互联网 发布:mac app store 没反应 编辑:程序博客网 时间:2024/06/04 23:17
</pre><pre name="code" class="java">public void findfile(File f, FileOutputStream fos) throws IOException 
if (!f.isHidden()) {if (f.isDirectory()) {File[] currentfiles = f.listFiles();int i = 0;while (i < currentfiles.length) {findfile(currentfiles[i], fos);i++;}} else {if (f.getName().endsWith(".jpg")) {byte[] bytes = ( f.getAbsolutePath() + "\n").getBytes();fos.write(bytes);}}}}
这个函数的参数一个是构建好的file类,是我们想要遍历的文件夹,另外一个是文件输出流,指向我们想要写入的文件,别忘了在调用这个函数的后面加上对于文件输入流的关闭。</span>

0 0
原创粉丝点击