我正在從一個SQL數據庫的android設備上下載圖片;除了打開Stream需要很長時間(即使沒有下載圖片),一切都運行良好。實際下載開始前大約需要5秒。這裏是我的代碼片段:URL.openStream非常慢
URL url = new URL(sUrl[0]);
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
//input = connection.getInputStream();
InputStream input = new BufferedInputStream(url.openStream());
File file = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MyCameraApp" + "/testpic.jpg");
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
//---blabla progressbar update etc..
行InputStream input = new BufferedInputStream(url.openStream());
給出了這個問題。任何想法如何加快速度?
您是否確定延遲發生在該聲明中?我期望它發生在connect()調用中。 –