我的代码只允许您保存下载到 SD 卡的文件,如何将下载保存在应用程序本身中?
编码:
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());
FileOutputStream fos = openFileOutput("try.pdf", Context.MODE_PRIVATE);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
fos.write(data, 0, count);
}
fos.flush();
fos.close();
input.close();
} catch (Exception e) {}
return null;
}
应该只改变这条路径就对了?