我有一个带有 gz 文件的 url,我需要下载这个文件并将其保存在手机内存中。如果没有互联网连接,我需要从内存中读取文件
public Document getDoc(String url1) throws IOException{
Document document = null;
try {
URL url = new URL(url1);
InputStream in = url.openStream();
GZIPInputStream zin;
try {
zin = (GZIPInputStream)in;
} catch (Exception e) {
zin = new GZIPInputStream(in);
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
document = db.parse(zin);
document.getDocumentElement().normalize();
} catch(Exception e) {
// Log.v(TAG, "Exception = " + e);
}
return document;
}