關於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 = ""; // 匹配相應的並用""(空字符串)替代 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; } } }