解决android sdk docs帮助文档打开慢的问题

解决android sdk docs帮助文档打开慢的问题

https://blog.csdn.net/yang5726685/article/details/80543849

经查是因为本地文档中的网页有如下两段js代码会联网加载信息,将其注释掉后就好了

[html] view plain copy
 
 
 
 
  1. <link rel="stylesheet"  
  2. href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" title="roboto">  

[html] view plain copy
 
 
 
 
  1. <script src="http://www.google.com/jsapi" type="text/javascript"></script>  

用以下java代码就可以批量注释,注意docs的目录要放在("D:/docs/");  
[java] view plain copy
 
 
 
 
  1. package teststr;  
  2.   
  3. /* 
  4.  * 去掉Android文档中需要联网的javascript代码 
  5.  */  
  6. import java.io.BufferedReader;  
  7. import java.io.BufferedWriter;  
  8. import java.io.File;  
  9. import java.io.FileNotFoundException;  
  10. import java.io.FileReader;  
  11. import java.io.FileWriter;  
  12. import java.io.IOException;  
  13.   
  14. public class FormatDoc {  
  15.     public static int j = 1;  
  16.   
  17.     /** 
  18.      * @param args 
  19.      */  
  20.     public static void main(String[] args) {  
  21.   
  22.         File file = new File("D:/docs/");  
  23.         searchDirectory(file, 0);  
  24.         System.out.println("OVER");  
  25.     }  
  26.   
  27.     public static void searchDirectory(File f, int depth) {  
  28.         if (!f.isDirectory()) {  
  29.             String fileName = f.getName();  
  30.             if (fileName.matches(".*.{1}html")) {  
  31.                 String src = "<(link rel)[=]"(stylesheet)" (href)[=]"(http)://(fonts.googleapis.com/css)[?](family)[=](Roboto)[:](regular,medium,thin,italic,mediumitalic,bold)"( title)[=]"roboto">";  
  32.                 String src1 = "<script src="http://www.google.com/jsapi" type="text/javascript"></script>";  
  33.                 String dst = "";  
  34.                 // 如果是html文件则注释掉其中的特定javascript代码  
  35.                 annotation(f, src, dst);  
  36.                 annotation(f, src1, dst);  
  37.             }  
  38.         } else {  
  39.             File[] fs = f.listFiles();  
  40.             depth++;  
  41.             for (int i = 0; i < fs.length; ++i) {  
  42.                 File file = fs[i];  
  43.                 searchDirectory(file, depth);  
  44.             }  
  45.         }  
  46.     }  
  47.   
  48.     /* 
  49.      * f 将要修改其中特定内容的文件 src 将被替换的内容 dst 将被替换层的内容 
  50.      */  
  51.     public static void annotation(File f, String src, String dst) {  
  52.         String content = FormatDoc.read(f);  
  53.         content = content.replaceFirst(src, dst);  
  54.         int ll = content.lastIndexOf(src);  
  55.         System.out.println(ll);  
  56.         FormatDoc.write(content, f);  
  57.         System.out.println(j++);  
  58.         return;  
  59.   
  60.     }  
  61.   
  62.     public static String read(File src) {  
  63.         StringBuffer res = new StringBuffer();  
  64.         String line = null;  
  65.         try {  
  66.             BufferedReader reader = new BufferedReader(new FileReader(src));  
  67.             int i = 0;  
  68.             while ((line = reader.readLine()) != null) {  
  69.                 if (i != 0) {  
  70.                     res.append(' ');  
  71.                 }  
  72.                 res.append(line);  
  73.                 i++;  
  74.             }  
  75.             reader.close();  
  76.         } catch (FileNotFoundException e) {  
  77.             e.printStackTrace();  
  78.         } catch (IOException e) {  
  79.             e.printStackTrace();  
  80.         }  
  81.         return res.toString();  
  82.     }  
  83.   
  84.     public static boolean write(String cont, File dist) {  
  85.         try {  
  86.             BufferedWriter writer = new BufferedWriter(new FileWriter(dist));  
  87.             writer.write(cont);  
  88.             writer.flush();  
  89.             writer.close();  
  90.             return true;  
  91.         } catch (IOException e) {  
  92.             e.printStackTrace();  
  93.             return false;  
  94.         }  
  95.     }  
  96. }
原文地址:https://www.cnblogs.com/it-tsz/p/10807488.html