Android下保存简单网页到本地(包括简单图片链接转换)(二)

2014-11-24 01:20:00 · 作者: · 浏览: 13
eToFirst();
int index1 = c.getColumnIndex("content_id");
int index2 = c.getColumnIndex("title");

while (!c.isAfterLast()) {
String id = c.getString(index1);
if(isHtmlSaved(id)) {
Subscribe sub = new Subscribe(
id,
c.getString(index2),
Subscribe.FILE_DOWNLOADED
);
list.add(sub);
}

c.moveToNext();
}
}

return list;
}

public void deleteHtml(String id) {
mDB.delete("download_html", "content_id= ", new String[]{id});
File dir_file = new File(mDownloadPath + id);
deleteFile(dir_file);
}


private void deleteFile(File file) {
if (file.exists()) { // 判断文件是否存在
if (file.isFile()) { // 判断是否是文件

file.delete(); // delete()方法 你应该知道 是删除的意思;
} else if (file.isDirectory()) { // 否则如果它是一个目录
File files[] = file.listFiles(); // 声明目录下所有的文件 files[];
for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
this.deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
}
}
file.delete();
} else {
//
}
}

private String formatPath(String path) {
if (path != null && path.length() > 0) {
path = path.replace("\\", "_");
path = path.replace("/", "_");
path = path.replace(":", "_");
path = path.replace("*", "_");
path = path.replace(" ", "_");
path = path.replace("\"", "_");
path = path.replace("<", "_");
path = path.replace("|", "_");
path = path.replace(">", "_");
}
return path;
}
}