Android 參考文檔本地開啟緩慢,JAVA解決方案,androidjava

來源:互聯網
上載者:User

Android 參考文檔本地開啟緩慢,JAVA解決方案,androidjava

關於Android Develop 文檔明明本地下載了,但在瀏覽器裡開啟還是很卡,原因是html文檔中有連結Google伺服器的Link和script。

網上有很多解決方案,其中一種是刪除裡面所有連結Google伺服器的Link和script。

我在網上下載的JAVA代碼這兩行修飾css代碼是怎麼也刪不掉,後來我讀完代碼發現有些bug.

<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Roboto+Condensed">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold"
title="roboto">

以下是我參考別人的代碼修改的JAVA代碼解決方案,與別人JAVA代碼的不同之處是能完全刪除所有連結Google伺服器的Link和script。

package deleteAndroidDoc;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("G:/Android 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(".*.{1}html")) {                String src = "<link rel=\"stylesheet\"";                String src1 = "href=\"http://fonts.googleapis.com/css\\?family=Roboto\\+Condensed\">";                String src2 = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";                String src3 = "<script src=\"https://developer.android.com/ytblogger_lists_unified.js\" type=\"text/javascript\"></script>";                String src4 = "<link rel=\"stylesheet\" href=\"http://fonts.googleapis.com/css\\?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold\"";                String src5 = "  title=\"roboto\">";                String dst = "";                // 匹配相應的並用""(Null 字元串)替代                annotation(f, src, dst);                annotation(f, src1, dst);                annotation(f, src2, dst);                annotation(f, src3, dst);                annotation(f, src4, dst);                annotation(f, src5, dst);            }        } else {            File[] fs = f.listFiles();            depth++;            for (int i = 0; i < fs.length; ++i) {                File file = fs[i];                searchDirectory(file, depth);            }        }    }    public static void annotation(File f, String src, String dst) {        String content = FormatDoc.read(f);        content = content.replaceFirst(src, dst);        int ll = content.lastIndexOf(src);        System.out.println(ll);        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;        }    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.