实现了小说章节的切割,并生成为html文件 package com.xll.transform;import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import
package com.xll.transform; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import org.junit.Test; /** * 切记源文件必须转换为utf-8格式,否则无法分解!!!! * @author MyComputer * */ public class Transform { /** * 储存章节名 */ Listtlist=new ArrayList (); /** * 储存章节 */ List llist=new ArrayList (); public void make(File file,String name){ read(file,name); write(name); menu(name); } private void menu(String name) { // TODO Auto-generated method stub } public void read(File file,String name){ String line=""; String body=""; try { FileInputStream input=null; Scanner scan=null; input=new FileInputStream(file); scan=new Scanner(input,"utf-8"); scan.useDelimiter("/n"); while(scan.hasNext()){ line=scan.nextLine().replaceFirst("正文", ""); if((line.contains("第"))&&(line.contains("章"))){ tlist.add(line); llist.add(body); body=""; body=body+line.concat("
"); } else{ body=body+line.concat("
"); } } scan.close(); llist.add(body); // System.out.println(llist.size()); write(name); } catch (FileNotFoundException e) { e.printStackTrace(); } } private void write(String name) { String body; int last=1; int next =0; String head="Insert title here "; // head=head.replaceFirst("[", ""); String fileName="G:\\大学实训.北京\\jsp_eclipse\\Novel1.0\\WebContent\\"+name+"/a"; for(int i=1;i