您的位置:首页 > 其它

小说按章节切割

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=======");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: