加速你的Android开发文档
Android4.2刚发布不久,更新了一下4.2的SDK,顺便更新了一下Documentation for Android SDK,真后悔更新这个文档。害得在Ubuntu10.10下用火狐打开页面错乱,而且打开奇慢无比,一直是一个白板,等接近10几秒才慢慢出来页面,而且其他子页面也都是奇慢无比!

我就很郁闷的,好好的文档,一下子就这么慢了,那今后要看文档就麻烦了,太耗时了。那个后悔呀。
后来想了想,不能这么慢,都下载好的本地html,于是看了看页面的源代码。明白了!

很明显,在打开本地文档前需要打开google的网站,google.com在中国打开慢,这不是我们需要争辩的话题。
那么,如何才能解决?答案很明显,要么断网,要么去掉这些网址。
本人觉得吧,闲每次看个文档断网太麻烦了。于是决定自己花些时间写个小工具,去除文档中的网址。
先看看写完的小工具吧。
下载地址:http://download.csdn.net/detail/xn4545945/4809848

由于处理的文件量比较大,有1W多个html文件。共计500M多一点,耗时比较长。构想对每一个文件开一个线程来进行处理,那就是考验CPU与内存的时候了。
部分主要代码:
package xu.neng.processor;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;/* * 调用一个独立的线程来处理单个html文件删除过程 */public class ProcessorThread extends Thread{// 传递过来的路径private File file;private String htmlContent = "http://blog.csdn.net/xn4545945";public ProcessorThread(){super();}public ProcessorThread(File file){super();this.file = file;}@Overridepublic void run(){try{String oldString1 = "http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold";String oldString2 = "http://www.google.com/jsapi";// 1. 从文件读取出字符串存放进htmlContentBufferedReader in = new BufferedReader(new FileReader(file));//这里按行来读并比对,设定字节数组应该会快一些.稍后再改.String temp = "";while ((temp = in.readLine()) != null){// 2. 从字符串中删除特定的内容, 并存入字符htmlContent中if (temp.contains(oldString1)){htmlContent = htmlContent + temp.replace(oldString1, "")+ "\n";} else if (temp.contains(oldString2)){htmlContent = htmlContent + temp.replace(oldString2, "")+ "\n";} else if (htmlContent.equals("http://blog.csdn.net/xn4545945")){htmlContent += "\n";} else{htmlContent = htmlContent + temp + "\n";}}// System.out.println(htmlContent);// 打印一下in.close();// 3. 将字符串写入文件BufferedWriter out = new BufferedWriter(new FileWriter(file));out.write(htmlContent);out.close();} catch (FileNotFoundException e){e.printStackTrace();} catch (IOException e){e.printStackTrace();}super.run();}}未完待续。。。。。。。明天再写,里面包含了一些多线程问题。
转载请注明出处:http://blog.csdn.net/xn4545945