A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 宋超2356 中级黑马   /  2014-6-3 16:12  /  1592 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 宋超2356 于 2014-6-3 16:14 编辑

去36期,要笔试,最近半月时间都在毕业设计答辩上,这java一点没看,无限心虚。{:3_55:}只好把毕老师35天的代码拷入手机在车上看。{:3_50:}
可是蛋疼的ios不支持文件夹的方式,必须直接传入txt,而那35天的代码各种包好多层...{:3_68:}
于是写一小程序把文件抽出来~方便导入手机~~分享给可能有这需要的童鞋~{:3_57:}
  1. import java.io.*;


  2. public class FileDemo {

  3.         /**
  4.          * @param args
  5.          * @throws IOException
  6.          */
  7.         public static void main(String[] args) throws IOException {
  8.                 File dir = new File("C://Users//Administrator//Desktop//Code");
  9.                 showDir(dir);

  10.         }
  11.         public static void showDir(File dir) throws IOException {
  12.                 File[] files = dir.listFiles();
  13.                 for(int x = 0;x<files.length;x++) {
  14.                         if(files[x].isDirectory()) showDir(files[x]);
  15.                         else {
  16.                                 //System.out.println(files[x]);
  17.                                 BufferedReader bur = new BufferedReader(new FileReader(files[x]));
  18.                                 String str = files[x].getName();
  19.                                 if(str.endsWith(".java")){
  20.                                         int i = str.indexOf(".");
  21.                                         str = str.substring(0, (i-1))+".txt";
  22.                                 }
  23.                                 BufferedWriter buw = new BufferedWriter(new FileWriter("E://s//"+ str ));
  24.                                 String s = null;
  25.                                 while((s = bur.readLine()) != null) {
  26.                                         buw.write(s);
  27.                                         buw.newLine();
  28.                                         buw.flush();
  29.                                 }
  30.                                 buw.close();
  31.                                 bur.close();
  32.                         }
  33.                        
  34.                 }
  35.                
  36.         }

  37. }
复制代码


未做异常处理

附毕老师35天的代码
http://pan.baidu.com/s/1jGzaxOq






9 个回复

倒序浏览
不错,谢谢你的分享!
回复 使用道具 举报
学以致用,哈哈。
回复 使用道具 举报
多谢分享
回复 使用道具 举报
多谢分享!
回复 使用道具 举报
多谢分享
回复 使用道具 举报
不错啊 !
回复 使用道具 举报
这也可以??、厉害!!!
回复 使用道具 举报
哈哈哈。给力
回复 使用道具 举报
多谢楼主啊
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马