[Android]_[初级]_[sdk docs reference api 文档打开慢的解决办法]


场景:

1. 下载sdk时下载了docs/reference文档,文档是html形式的,因为里面带有google的相关网址,浏览器打开时会去访问这些被墙的网址,所以显示巨慢。

2. 解决办法就是遍历子目录删除google相关网址,由于是android开发,就用Java实现吧.

3.以下运行用时9分钟,i5双核,4G内存,开了其他东西,最新的sdk docs,android 5L.


文件.Cleaner.java

import java.io.*;


public class Cleaner
{


	public static void main(String[] args) {
		System.out.println("begin to clean google.com;googleapis.com;google-analytics.com");
		String currentDir = args[0];

		Cleaner c = new Cleaner();
		c.work(currentDir);
		System.out.println("end to clean google.com;googleapis.com;google-analytics.com");	
	}

	public Cleaner(){}

	public void work(String currentDir){
		File file = new File(currentDir);
		deleteReference(file);
	}

	public void deleteReference(File file)
	{
		String[] files = file.list();
		String path = file.getPath();
		for (String one : files) {
			String filePath = path+File.separatorChar+one;
			// System.out.println(filePath);	
			File fileTemp = new File(filePath);	
			if(fileTemp.isDirectory())
			{
				deleteReference(fileTemp);
			}else{
				// delete google reference
				if(filePath.endsWith(".html"))
				{
					try
					{
						BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileTemp),"UTF-8"));

						filePath = filePath+".tmp";
						File newFile = new File(filePath);
						BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile),"UTF-8"));
						String line = null;
						while((line = br.readLine())!= null)
						{
							String newLine = line.replaceAll("google\\.com|googleapis\\.com|google-analytics\\.com","");
							bw.write(newLine);
							bw.newLine();
						}
						br.close();
						bw.close();
						fileTemp.delete();
						newFile.renameTo(fileTemp);
					}catch(Exception e)
					{
						e.printStackTrace();
					}
				}
			}		
		}	
	}

}


编译执行:

C:\Users\Admin\Desktop>javac Cleaner.java & java Cleaner E:\software\adt\sdk\docs\reference
begin to clean google.com;googleapis.com;google-analytics.com
end to clean google.com;googleapis.com;google-analytics.com



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。