简单的代码,测试至少是可行
原创内容如转载请注明:来自 阿权的书房
public static void downloadFile(String url, String newPath) {
URL myFileUrl = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
Log.e("test", "MalformedURLException: "+e.toString() );
}
try {
HttpURLConnection conn;
conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
FileOutputStream newfile = new FileOutputStream("/sdcard/tmp.apk");
byte[] buffer = new byte[1444];
int byteread = 0;
while ( (byteread = is.read(buffer)) != -1) {
newfile.write(buffer, 0, byteread);
}
is.close();
} catch (Exception e) {
Log.e("test", "returnNetworkBitMap: "+e.toString() );
}finally{
}
}
URL myFileUrl = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
Log.e("test", "MalformedURLException: "+e.toString() );
}
try {
HttpURLConnection conn;
conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
FileOutputStream newfile = new FileOutputStream("/sdcard/tmp.apk");
byte[] buffer = new byte[1444];
int byteread = 0;
while ( (byteread = is.read(buffer)) != -1) {
newfile.write(buffer, 0, byteread);
}
is.close();
} catch (Exception e) {
Log.e("test", "returnNetworkBitMap: "+e.toString() );
}finally{
}
}
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
android程序安装和卸载
Request对象错误ASP 0104:80004005不允许操作
