小石頭
          Excellence in any department can be attained only by the labor of a lifetime; it is not to be purchased at a lesser price.
          posts - 91,comments - 22,trackbacks - 0
          import ?java.io.BufferedReader;
          import ?java.io.File;
          import ?java.io.FileReader;
          import ?java.io.FileWriter;
          import ?java.io.IOException;
          import ?java.util.ArrayList;
          import ?java.util.HashMap;

          /**
          ?*?<p>
          ?*?文件名稱:?GenerateBook.java
          ?*?</p>
          ?*?<p>
          ?*?文件描述:?無
          ?*?</p>
          ?*?<p>
          ?*?版權(quán)所有:?版權(quán)所有(C)2001-2004
          ?*?</p>
          ?*?<p>
          ?*?公?司:?
          ?*?</p>
          ?*?<p>
          ?*?內(nèi)容摘要:?無
          ?*?</p>
          ?*?<p>
          ?*?其他說明:?無
          ?*?</p>
          ?*?<p>
          ?*?創(chuàng)建日期:2007-2-14
          ?*?</p>
          ?*?<p>
          ?*?完成日期:2007-2-14
          ?*?</p>
          ?*?<p>
          ?*?修改記錄1:?//?修改歷史記錄,包括修改日期、修改者及修改內(nèi)容
          ?*?</p>
          ?*?
          ?*?<pre>
          ?*?????修改日期:
          ?*?????版?本?號:
          ?*?????修?改?人:
          ?*?????修改內(nèi)容:
          ?*?</pre>
          ?*?
          ?*?<p>
          ?*?修改記錄2:…
          ?*?</p>
          ?*?
          ?*?
          @version ?1.0
          ?*?
          @author ?yangv
          ?
          */


          public ? class ?GenerateBook? {

          ????File?bookFile?
          = ? null ;

          ????
          public ?GenerateBook(File?bookFile)? {
          ????????
          this .bookFile? = ?bookFile;
          ????}


          ????
          public ?ArrayList?getLogContentText()? {
          ????????FileReader?reader?
          = ? null ;
          ????????ArrayList?list?
          = ? new ?ArrayList();
          ????????
          // ?HashMap?map?=?new?HashMap();

          ????????
          try ? {
          ????????????reader?
          = ? new ?FileReader(bookFile);
          ????????????BufferedReader?br?
          = ? new ?BufferedReader(reader);
          ????????????String?s1?
          = ? null ;
          ????????????StringBuffer?result?
          = ? new ?StringBuffer( "" );
          ????????????
          while ?((s1? = ?br.readLine())? != ? null )? {
          ????????????????
          if ?(s1.indexOf( " 部? " )? != ? - 1 ? && ?s1.indexOf( " " )? != ? - 1 )? {
          ????????????????????
          if ?(result.length()? > ? 0 )? {
          ????????????????????????list.add(result.toString());
          ????????????????????????log(result.toString());
          ????????????????????}

          ????????????????????result?
          = ? new ?StringBuffer( "" );
          ????????????????????result.append(s1?
          + ? " \n " );
          ????????????????}
          ? else ? {
          ????????????????????result.append(s1?
          + ? " \n " );
          ????????????????}

          ????????????}

          ????????????log(result.toString());
          ????????????br.close();
          ????????????reader.close();
          ????????}
          ? catch ?(Exception?ex)? {
          ????????????ex.printStackTrace();
          ????????}

          ????????
          return ?list;
          ????}


          ????
          public ? void ?log(String?content)? {
          ????????
          // ?System.out.println("\\------------------------\\");
          ????????
          // ?int?i=?content.indexOf("\n");
          ????????
          // ?System.out.println(content.substring(0,i));
          ????}


          ????
          /**
          ?????*?
          @param ?args
          ?????
          */

          ????
          public ? static ? void ?main(String[]?args)? {
          ????????
          // ?GenerateBook?book?=?new?GenerateBook(new?File("21839.txt"));
          ????????GenerateBook?book? = ? new ?GenerateBook( new ?File( " 21839.txt " ));
          ????????ArrayList?list?
          = ?book.getLogContentText();
          ????????
          for ?( int ?i? = ? 0 ;?i? < ?list.size();?i ++ )? {
          ????????????String?content?
          = ?list.get(i).toString();
          ????????????
          int ?m? = ?content.indexOf( " \n " );
          ????????????
          int ?n? = ?content.indexOf( " " );
          ????????????writeFile(content,
          new ?File(content.substring(n,?m).replaceAll( " ???? " ,? "" ).replaceAll( " " ,? "" ).trim() + " .txt " ));
          ????????????System.out.println(content.substring(n,?m).trim());
          ????????}

          ????}


          ????
          public ? static ? void ?writeFile(String?content,?File?file)? {
          ????????FileWriter?writer?
          = ? null ;
          ????????
          try ? {
          ????????????writer?
          = ? new ?FileWriter(file.getAbsolutePath());
          ????????????writer.write(content);
          ????????????writer.close();
          ????????}
          ? catch ?(IOException?ex1)? {
          ????????????ex1.printStackTrace();
          ????????}


          ????}


          }

          posted on 2007-02-15 20:38 小石頭 閱讀(609) 評論(0)  編輯  收藏 所屬分類: 每天學(xué)一點(diǎn)
          主站蜘蛛池模板: 曲靖市| 息烽县| 佳木斯市| 福贡县| 沾化县| 开封县| 新兴县| 锡林浩特市| 湛江市| 赣榆县| 江阴市| 宁国市| 济阳县| 勃利县| 黎城县| 浪卡子县| 洛川县| 新乡市| 元氏县| 于田县| 凤冈县| 邵武市| 洛川县| 崇仁县| 庄浪县| 新干县| 平安县| 舞阳县| 千阳县| 汶川县| 富川| 永嘉县| 开阳县| 巴青县| 同德县| 类乌齐县| 大同县| 娄烦县| 台南市| 图木舒克市| 辽源市|