小石头
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>
 * 版权所有: 版权所有(C)2001-2004
 * </p>
 * <p>
 * 公 司: 
 * </p>
 * <p>
 * 内容摘要: 无
 * </p>
 * <p>
 * 其他说明: 无
 * </p>
 * <p>
 * 创建日期:2007-2-14
 * </p>
 * <p>
 * 完成日期:2007-2-14
 * </p>
 * <p>
 * 修改记录1: // 修改历史记录,包括修改日期、修改者及修改内容
 * </p>
 * 
 * <pre>
 *     修改日期:
 *     版 本 号:
 *     修 改 人:
 *     修改内容:
 * </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 小石头 阅读(593) 评论(0)  编辑  收藏 所属分类: 每天学一点

只有注册用户登录后才能发表评论。


网站导航: