1
我想通過url下載zip文件。我想在不寫入SD卡的情況下對其進行加密。如何從網址獲取完整的字節數據? 在此先感謝如何將完整數據下載到字節數組中
protected String doInBackground(String... url) {
int count;
try {
URL url1 = new URL(url[0]);
URLConnection conexion = url1.openConnection();
conexion.connect();
// this will be useful so that you can show a tipical 0-100%
// progress bar
int lenghtOfFile = conexion.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url1.openStream());
OutputStream output = new FileOutputStream(
"/sdcard/downloaded.zip");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
publishProgress((int) (total * 100/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
}
return null;
}
我希望你明白,你的手機上有一個有限的內存 – the100rabh 2012-02-21 04:57:05
@ the100rabh:雅。我知道..但我的問題是在寫入SD卡之前加密數據。 – 2012-02-21 04:59:53