Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發實例 >> android幫助文檔打開慢的三種解決方法

android幫助文檔打開慢的三種解決方法

編輯:Android開發實例

經查是因為本地文檔中的網頁有如下js代碼會聯網加載信息,將其注釋掉後就好了

代碼如下:

<script src="http://www.google.com/jsapi" type="text/javascript"></script>

用一下java代碼就可以批量注釋

代碼如下:

package cn.sd.fxd.android;

/*
 * 去掉Android文檔中需要聯網的javascript代碼
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FormatDoc {
    public static int j=1;
    /**
     * @param args
     */
    public static void main(String[] args) {

        File file = new File("D:/android/android-sdk-windows/docs/");
        searchDirectory(file, 0);
        System.out.println("OVER");
    }

    public static void searchDirectory(File f, int depth) {
        if (!f.isDirectory()) {
            String fileName = f.getName();
            if (fileName.matches(".*?.html")) {
                String src = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";
                String dst = "<!-- <script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script> -->";
                //如果是html文件則注釋掉其中的特定javascript代碼
                annotation(f, src, dst);
            }
        } else {
            File[] fs = f.listFiles();
            depth++;
            for (int i = 0; i < fs.length; ++i) {
                File file = fs[i];
                searchDirectory(file, depth);
            }
        }
    }

    /*
     * f 將要修改其中特定內容的文件
     * src 將被替換的內容
     * dst 將被替換層的內容
     */
    public static void annotation(File f, String src, String dst) {
        String content = FormatDoc.read(f);
        content = content.replaceAll(src, dst);
        FormatDoc.write(content, f);
        System.out.println(j++);
        return;

    }

    public static String read(File src) {
        StringBuffer res = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(src));
            int i=0;
            while ((line = reader.readLine()) != null) {
                if (i!=0) {
                    res.append('\n');
                }
                res.append(line);
                i++;
            }
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res.toString();
    }

    public static boolean write(String cont, File dist) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(dist));
            writer.write(cont);
            writer.flush();
            writer.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

網上有種方法是通過shell刪除那行js代碼,非常簡潔方便,比我寫的java方便100倍,I HATE JAVA

代碼如下:

find . -name "*.html"|xargs grep -l "jsapi"|xargs sed -i '/jsapi/d'

還有的方法是斷網,或者用IE,firefox脫機浏覽

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved