我正在使用URLConnection
将文件下载到SD卡上。这很好,但我认为HTTPClient
会更好。那我该怎么做?
URL url = new URL( aurl[0] );
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d( "ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile );
InputStream input = new BufferedInputStream( url.openStream() );
OutputStream output = new FileOutputStream( ApkFileDirectory );
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read( data )) != -1) {
total += count;
publishProgress( "" + (int) ((total * 100) / lenghtOfFile) );
output.write( data, 0, count );
}
output.flush();
output.close();
input.close();