日期:2014-05-20 浏览次数:20851 次
import java.io.*; class TestP { public static void main(String[] args) { File s = new File("e:/1"); log(s); Play(s); } public static void Play(File f) { File[] child = f.listFiles(); for(int i = 0;i < child.length;i++){ if(child[i].isDirectory()){ log(child[i]); Play(child[i]); } } } public static void log(File currentFile){ String[] s = currentFile.list(); for(int i = 0; i < s.length;i++){ StringBuffer sb = new StringBuffer(); File temp = new File("f:/",currentFile.getName()+".txt"); FileWriter wri = null; try { wri = new FileWriter(temp); } catch (IOException e) { e.printStackTrace(); } BufferedWriter bw = new BufferedWriter(wri); for(String a:s){ sb.append(a); sb.append("\n"); } try { bw.write(sb.toString()); } catch (IOException e) { e.printStackTrace(); } try { bw.flush(); } catch (IOException e) { e.printStackTrace(); } }//close for } }
------解决方案--------------------
数组方式可能更快,一行行读慢: