小说按章节切割
2015-10-30 00:00
169 查看
摘要: 章节切割,什么回,卷,不考虑
public void cut(String srcFilePath,String dstDir,String code){ BufferedReader br=null; BufferedWriter bw=null; try { br=new BufferedReader(new InputStreamReader(new FileInputStream(srcFilePath),code)); String tempString=null; StringBuffer sb=new StringBuffer(); Pattern p=Pattern.compile("第.*章"); Matcher m=null; Integer index=0; int i=0; File file; while((tempString=br.readLine())!=null){ tempString+="\r\n"; sb.append(tempString); } m=p.matcher(sb); while(m.find()){ i++; file=new File(dstDir + File.separator + i +".txt"); bw=new BufferedWriter(new FileWriter(file)); int start = m.start(); if(m.find()){ index=m.start(); bw.write(sb.toString(),start, index-start); bw.flush(); m.region(index,sb.length()); }else{ bw.write(sb.toString(),start, sb.length()-start); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch(IOException ie){ ie.printStackTrace(); } finally{ try { if(br!=null){ br.close(); } if(bw!=null){ bw.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("========END======="); }
相关文章推荐
- 在android的spinner中,实现取VALUE值和TEXT值
- 使用ncdu1.11,安装ncurses5.9,安装g++
- 轻码云云通讯助推移动医疗发展解决民生大事
- XXX面试题
- 手机端适配代码
- linux tar 解压命令总结
- hadoop2x WordCount MapReduce
- Hadoop 数据类型
- ueditor编辑器配置及使用介绍
- iOS中属性与成员变量的区别
- Objective-C的属性和成员变量用法及关系浅析
- ios推送消息的基本原理
- SOLR管理配置和性能优化JVM参数调优
- 测试利器Mocha
- mariadb-galera-cluster脑裂
- 如何正确关机和重启服务器?
- Visual EmbedLinux Tools:让vs支持嵌入式Linux开发
- LeetCode——Minimum Path Sum
- 解决 Missing artifact mina-core:bundle
- 静态百度页面