Android帮助文档打开慢的解决方法

1. 打开index.html,然后注释掉两个地方 stylesheet和js两个地方:
<!--<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" title="roboto">-->
<!--<script src="http://www.google.com/jsapi" type="text/javascript"></script>-->

然后保存


2. C:\Windows\System32\drivers\etc\HOSTS
增加如下部分,瞬间提速
127.0.0.1 fonts.googleapis.com
127.0.0.1 www.google.com


3. 实现批量注释的java代码:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值