当前位置:   article > 正文

系统集成项目管理工程师教程(第2版)带书签目录

系统集成项目管理工程师教程 第2版 txt

[官方指定考试教材]
系统集成项目管理工程师教程(第2版)带书签目录 

链接:https://pan.baidu.com/s/1qZi2YSG 密码:5q57

鉴于最近考试所需,考信息系统项目管理师的,也要把《系统集成项目管理工程师教程》学完,无奈网上的这本书都是没有书签目录的,要么就是带广告水印的,于是花了2天多的时间自己制作了一套书目录,现分享给有需要的朋友。

具体代码:

  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.regex.Pattern;
  8. import org.apache.log4j.Logger;
  9. public class ReadAndWriteFile {
  10. static Logger log = Logger.getLogger(ReadAndWriteFile.class);
  11. public static int getPointCount(String string, String a) {
  12. String[] array = string.split(a);
  13. if (array != null) {
  14. if(!string.contains(".N")){
  15. return (array.length - 1);
  16. }else{
  17. return (array.length - 1)-1;
  18. }
  19. }
  20. return 0;
  21. }
  22. public static void readFileAndWriteFile(String fileName){
  23. File file = new File(fileName);
  24. BufferedReader reader = null;
  25. try {
  26. // System.out.println("以行为单位读取文件内容,一次读一整行:");
  27. reader = new BufferedReader(new FileReader(file));
  28. String temp = null;
  29. String temp1 = null;
  30. String marker = "<书签 页码=\"PageNum\" 文本=\"TitleContent\" 动作=\"转到页面\" 显示方式=\"坐标缩放\" 左=\"null\" 上=\"null\">";
  31. String markerEnd = "</书签>";
  32. String markerStartAndEnd = "<书签 页码=\"PageNum\" 文本=\"TitleContent\" 动作=\"转到页面\" 显示方式=\"坐标缩放\" 左=\"null\" 上=\"null\" />";
  33. int line = 1;
  34. int titleLevel;
  35. List<String[]> list = new ArrayList<String[]>();//存储书签目录
  36. // 一次读入一行,直到读入null为文件结束
  37. while ((temp = reader.readLine()) != null) {
  38. String[] ss = new String[3];//[0]目录等级,[1]跳转页码,[2]标题
  39. // 显示行号
  40. // System.out.println("line " + line + ": " + temp);
  41. temp = temp.trim();
  42. int pageNum = 0;//跳转页码
  43. String titleContent = "";//标题
  44. temp1 = temp;
  45. // temp1.replaceAll(".*[^\\d](?=(\\d+))","");//比如一个字符串:String filter = "1234gogogo67890",我想只获取后面的数字:即:67890。
  46. pageNum = Integer.parseInt(temp1.replaceAll(".*[^\\d](?=(\\d+))",""))+36;//22是偏移值
  47. titleContent = temp.substring(0,temp.length()-(pageNum+"").length());
  48. int isPointCount = getPointCount(temp, "\\.");
  49. String regEx="第*章";
  50. boolean result=Pattern.compile(regEx).matcher(temp).find();
  51. if(result){
  52. titleLevel = 1;
  53. ss[0]=titleLevel+"";
  54. }
  55. if(isPointCount == 1){
  56. titleLevel = 2;
  57. ss[0]=titleLevel+"";
  58. }else if(isPointCount == 2){
  59. titleLevel = 3;
  60. ss[0]=titleLevel+"";
  61. }
  62. ss[1]=pageNum+"";
  63. ss[2]=titleContent.trim();
  64. list.add(ss);
  65. line++;
  66. }
  67. reader.close();
  68. for(int i=0;i<list.size();i++){
  69. // System.out.println(list.get(i)[0]+","+list.get(i)[1]+","+list.get(i)[2]);
  70. // int j = (i-1)>=0?(i-1):0;//上一标题
  71. //i 本地标题
  72. int k = (i+1)<list.size()?(i+1):(list.size()-1);//下一标题
  73. String tmp = "";
  74. if(list.get(i)[0].equals("1")){//本级标题级别
  75. if(list.get(k)[0].equals("1")){//下一级级别
  76. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  77. }else if(list.get(k)[0].equals("2")){//下一级级别
  78. tmp = marker.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  79. }
  80. System.out.println(tmp);
  81. }
  82. if(list.get(i)[0].equals("2")){//本级标题级别
  83. if(list.get(k)[0].equals("1")){//下一级级别
  84. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  85. System.out.println("\t"+tmp);
  86. System.out.println(markerEnd);
  87. }else if(list.get(k)[0].equals("2")){//下一级级别
  88. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  89. System.out.println("\t"+tmp);
  90. }else if(list.get(k)[0].equals("3")){//下一级级别
  91. tmp = marker.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  92. System.out.println("\t"+tmp);
  93. }
  94. }
  95. if(list.get(i)[0].equals("3")){//本级标题级别
  96. if(list.get(k)[0].equals("1")){//下一级级别
  97. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  98. System.out.println("\t"+"\t"+tmp);
  99. System.out.println("\t"+markerEnd);
  100. System.out.println(markerEnd);
  101. }else if(list.get(k)[0].equals("2")){//下一级级别
  102. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  103. System.out.println("\t"+"\t"+tmp);
  104. System.out.println("\t"+markerEnd);
  105. }else if(list.get(k)[0].equals("3")){//下一级级别
  106. tmp = markerStartAndEnd.replace("PageNum", list.get(i)[1]).replace("TitleContent", list.get(i)[2]);
  107. System.out.println("\t"+"\t"+tmp);
  108. }
  109. }
  110. if(i==(list.size()-1)){
  111. if(list.get(i)[0].equals("1")){//本级标题级别
  112. }
  113. if(list.get(i)[0].equals("2")){//本级标题级别
  114. System.out.println(markerEnd);
  115. }
  116. if(list.get(i)[0].equals("3")){//本级标题级别
  117. System.out.println("\t"+markerEnd);
  118. System.out.println(markerEnd);
  119. }
  120. }
  121. }
  122. } catch (IOException e) {
  123. e.printStackTrace();
  124. } finally {
  125. if (reader != null) {
  126. try {
  127. reader.close();
  128. } catch (IOException e1) {
  129. }
  130. }
  131. }
  132. }
  133. public static void main(String[] args) {
  134. // readFileAndWriteFile("D:\\1111.txt");
  135. // readFileAndWriteFile("D:\\2222.txt");
  136. // readFileAndWriteFile("D:\\3333.txt");
  137. readFileAndWriteFile("D:\\4444.txt");
  138. }
  139. }

 

转载于:https://my.oschina.net/90888/blog/823426

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/281872
推荐阅读
相关标签
  

闽ICP备14008679号