首页 / 操作系统 / Linux / Android 参考文档本地打开缓慢,Java解决方案
关于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("
");
}
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;
}
}
}更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/129191.htm