黑马程序员技术交流社区

标题: 参加笔试前在火车上复习的好办法~ [打印本页]

作者: 宋超2356    时间: 2014-6-3 16:12
标题: 参加笔试前在火车上复习的好办法~
本帖最后由 宋超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







作者: hengxing0079    时间: 2014-6-3 17:46
不错,谢谢你的分享!
作者: AntThinking_toT    时间: 2014-6-3 19:20
学以致用,哈哈。
作者: 凌羽猎风    时间: 2014-6-3 21:54
多谢分享
作者: 诺诺    时间: 2014-6-4 10:48
多谢分享!
作者: 363758086ed    时间: 2014-6-4 21:34
多谢分享

作者: 363758086ed    时间: 2014-6-5 00:30
不错啊 !
作者: 茄子    时间: 2014-6-5 08:34
这也可以??、厉害!!!
作者: 菠萝包丶    时间: 2014-6-5 10:00
哈哈哈。给力
作者: 汤姆纳斯    时间: 2014-6-5 19:46
多谢楼主啊




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2