有三种方法:
1.离线查看,不联网;(好像没什么用,也不是很快)
2.使用浏览器中的脱机浏览,有效,速度很快。(不过会出现最上面那些Menu没有出现的情况)
3.由于本地文档中的网页有如下js代码会联网加载信息,所以只要将其注释掉就可以了。
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
使用eclipse运行以下的java代码(在命令行里面也是可以的)
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;
/**
* 去掉Android离线文档中需要联网的js代码
* @author KalinaRain
*/
public class FormatAndroidDoc {
public static int j=0;
public static void main(String args[]){
File file =new File("C:\\MySoftWare\\AndroidDev\\sdk\\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)\"\n(href)[=]\"(http)://(fonts.googleapis.com/css)[?](family)[=](Roboto)[:](regular,medium,thin,italic,mediumitalic,bold)\"( title)[=]\"roboto\">";
String src1 = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";
String dst = "";
//如果是html文件则注释掉其中的特定javascript代码
annotation(f, src, dst);
annotation(f, src1, 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 = FormatAndroidDoc.read(f);
content = content.replaceFirst(src, dst);
int ll=content.lastIndexOf(src);
System.out.println(ll);
FormatAndroidDoc.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;
}
}
}
这个方法还是有效的,不过可能有一些链接不可以访问了。
4.使用shell代码
通过shell删除那行js代码,非常简洁方便,比上面的的java方便100倍,不过不能删掉第一段js代码。
find . -name "*.html"|xargs grep -l "jsapi"|xargs sed -i '/jsapi/d'
find . -name "*.html"|xargs grep -l "jsapi"|xargs sed -i '/jsapi/d'
不过网上似乎没有比较全的方法,所以我也就没写