日期:2014-05-20 浏览次数:20617 次
package test; import java.io.File; import java.io.FileOutputStream; public class Search { StringBuffer str = new StringBuffer(); public static void main(String[] args) { try { Search s = new Search(); s.search(new File("D:\\")); String name = s.str.toString(); File file = new File("D:\\name.txt"); FileOutputStream fos = new FileOutputStream(file); fos.write(name.getBytes()); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } } public void search(File file) { if (file.isFile()) { str.append(file.getName()); } else { File[] files = file.listFiles(); for (File f : files) { search(f); } } } }
------解决方案--------------------
命令行
dir /s/b d: >> f:\files.txt