我正在使用metaio增强的reallity开发一个Android应用程序。好吧,在我的应用程序中,我要从网址下载一些图像。但是当我这样做时,我遇到了一个错误,它只获得了文件的一部分。
我有这个:
04-30 14:43:25.625: W/ExternalStorage(14181): Error writing /mnt/sdcard/Android/data/com.augmentedwine/files/Download/LOL.jpg
04-30 14:43:25.625: W/ExternalStorage(14181): java.io.IOException: stream closed
04-30 14:43:25.625: W/ExternalStorage(14181): at libcore.net.http.AbstractHttpInputStream.checkNotClosed(AbstractHttpInputStream.java:68)
04-30 14:43:25.625: W/ExternalStorage(14181): at libcore.net.http.FixedLengthInputStream.available(FixedLengthInputStream.java:59)
04-30 14:43:25.625: W/ExternalStorage(14181): at com.augmentedwine.view.ARActivity.createExternalStoragePrivatePicture(ARActivity.java:325)
04-30 14:43:25.625: W/ExternalStorage(14181): at com.augmentedwine.view.ARActivity$1.run(ARActivity.java:254)
04-30 14:43:25.625: W/ExternalStorage(14181): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1434)
04-30 14:43:25.625: W/ExternalStorage(14181): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
在此功能中:
void createExternalStoragePrivatePicture(String url) throws MalformedURLException, IOException {
File path = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, "LOL.jpg");
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();
try {
InputStream is = input;
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
Log.d("Size", "Tamanho " + is.available());
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (IOException e) {
// Unable to create file, likely because external storage is
// not currently mounted.
Log.w("ExternalStorage", "Error writing " + file, e);
}
}
你能帮帮我吗?
非常感谢。