[官方指定考试教材]
系统集成项目管理工程师教程(第2版)带书签目录
链接:https://pan.baidu.com/s/1qZi2YSG 密码:5q57
鉴于最近考试所需,考信息系统项目管理师的,也要把《系统集成项目管理工程师教程》学完,无奈网上的这本书都是没有书签目录的,要么就是带广告水印的,于是花了2天多的时间自己制作了一套书目录,现分享给有需要的朋友。
具体代码:
-
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.regex.Pattern;
-
- import org.apache.log4j.Logger;
-
- public class ReadAndWriteFile {
- static Logger log = Logger.getLogger(ReadAndWriteFile.class);
-
- public static int getPointCount(String string, String a) {
- String[] array = string.split(a);
- if (array != null) {
- if(!string.contains(".N")){
- return (array.length - 1);
- }else{
- return (array.length - 1)-1;
- }
- }
- return 0;
- }
-
- public static void readFileAndWriteFile(String fileName){
- File file = new File(fileName);
- BufferedReader reader = null;
- try {
- // System.out.println("以行为单位读取文件内容,一次读一整行:");
- reader = new BufferedReader(new FileReader(file));
- String temp = null;
- String temp1 = null;
- String marker = "<书签 页码=\"PageNum\" 文本=\"TitleContent\" 动作=\"转到页面\" 显示方式=\"坐标缩放\" 左=\"null\" 上=\"null\">";
- String markerEnd = "</书签>";
- String markerStartAndEnd = "<书签 页码=\"PageNum\" 文本=\"TitleContent\" 动作=\"转到页面\" 显示方式=\"坐标缩放\" 左=\"null\" 上=\"null\" />";
- int line = 1;
- int titleLevel;
- List<String[]> list = new ArrayList<String[]>();//存储书签目录
-
- // 一次读入一行,直到读入null为文件结束
- while ((temp = reader.readLine()) != null) {
- String[] ss = new String[3];//[0]目录等级,[1]跳转页码,[2]标题
- // 显示行号
- // System.out.println("line " + line + ": " + temp);
- temp = temp.trim();
- int pageNum = 0;//跳转页码
- String titleContent = "";//标题
- temp1 = temp;
- // temp1.replaceAll(".*[^\\d](?=(\\d+))","");//比如一个字符串:String filter = "1234gogogo67890",我想只获取后面的数字:即:67890。
- pageNum = Integer.parseInt(temp1.replaceAll(".*[^\\d](?=(\\d+))",""))+36;//22是偏移值
- titleContent = temp.substring(0,temp.length()-(pageNum+"").length());
-
- int isPointCount = getPointCount(temp, "\\.");
-
- String regEx="第*章";
- boolean result=Pattern.compile(regEx).matcher(temp).find();
-
- if(result){
- titleLevel = 1;
- ss[0]=titleLevel+"";
- }
- if(isPointCount == 1){
- titleLevel = 2;
- ss[0]=titleLevel+"";
- }else if(isPointCount == 2){
- titleLevel = 3;
- ss[0]=titleLevel+"";
- }
- ss[1]=pageNum+"";
- ss[2]=titleContent.trim();
- list.add(ss);
- line++;
- }
- reader.close();
-
- for(int i=0;i<list.size();i++){
- // System.out.println(list.get(i)[0]+","+list.get(i)[1]+","+list.get(i)[2]);
- // int j = (i-1)>=0?(i-1):0;//上一标题
- //i 本地标题
- int k = (i+1)<list.size()?(i+1):(list.size()-1);//下一标题
- String tmp = "";
-
- if(list.get(i)[0].equals("1")){//本级标题级别
- if(list.get(k)[0].equals("1")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- }else if(list.get(k)[0].equals("2")){//下一级级别
- tmp = marker.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- }
- System.out.println(tmp);
- }
-
- if(list.get(i)[0].equals("2")){//本级标题级别
- if(list.get(k)[0].equals("1")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+tmp);
- System.out.println(markerEnd);
- }else if(list.get(k)[0].equals("2")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+tmp);
- }else if(list.get(k)[0].equals("3")){//下一级级别
- tmp = marker.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+tmp);
- }
- }
-
- if(list.get(i)[0].equals("3")){//本级标题级别
- if(list.get(k)[0].equals("1")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+"\t"+tmp);
- System.out.println("\t"+markerEnd);
- System.out.println(markerEnd);
- }else if(list.get(k)[0].equals("2")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+"\t"+tmp);
- System.out.println("\t"+markerEnd);
- }else if(list.get(k)[0].equals("3")){//下一级级别
- tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
- System.out.println("\t"+"\t"+tmp);
- }
- }
-
- if(i==(list.size()-1)){
- if(list.get(i)[0].equals("1")){//本级标题级别
-
- }
- if(list.get(i)[0].equals("2")){//本级标题级别
- System.out.println(markerEnd);
- }
- if(list.get(i)[0].equals("3")){//本级标题级别
- System.out.println("\t"+markerEnd);
- System.out.println(markerEnd);
- }
-
- }
- }
-
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e1) {
- }
- }
- }
-
- }
-
- public static void main(String[] args) {
- // readFileAndWriteFile("D:\\1111.txt");
- // readFileAndWriteFile("D:\\2222.txt");
- // readFileAndWriteFile("D:\\3333.txt");
- readFileAndWriteFile("D:\\4444.txt");
- }
- }