关于Android Develop 文档明明本地下载了,但在浏览器里打开还是很卡,原因是html文档中有链接Google服务器的Link和script。
网上有很多解决方案,其中一种是删除里面所有链接Google服务器的Link和script。
我在网上下载的JAVA代码这两行修饰css代码是怎么也删不掉,后来我读完代码发现有些bug.
<link
href="http://fonts.googleapis.com/css?family=Roboto+Condensed">
<link href="https://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=https://www.linuxidc.com/Linux/2016-03/\"stylesheet\"";
String src1 = "href=https://www.linuxidc.com/Linux/2016-03/\"http://fonts.googleapis.com/css\\?family=Roboto\\+Condensed\">";
String src2 = "<script src=https://www.linuxidc.com/Linux/2016-03/\"http://www.google.com/jsapi\" type=https://www.linuxidc.com/Linux/2016-03/\"text/javascript\"></script>";
String src3 = "<script src=https://www.linuxidc.com/Linux/2016-03/\"https://developer.android.com/ytblogger_lists_unified.js\" type=https://www.linuxidc.com/Linux/2016-03/\"text/javascript\"></script>";
String src4 = "<link rel=https://www.linuxidc.com/Linux/2016-03/\"stylesheet\" href=https://www.linuxidc.com/Linux/2016-03/\"http://fonts.googleapis.com/css\\?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold\"";
String src5 = " title=https://www.linuxidc.com/Linux/2016-03/\"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();
}