我從服務器得到一個url &我想在我的android htc設備中保存視頻。 我收到一些錯誤:----- java.io.FileNotFoundException:/mnt/sdcard/543b8417-6e67-4755-8c68-b93373f9d9e2.wmv(權限被拒絕) &不支持地址系列。 我已經在清單文件中給予所有權限。我的代碼是: - videoUrl =「http://125.63.71.222/fliptest/uservideo/543b8417-6e67-4755-8c68-b93373f9d9e2.wmv」;如何從服務器中保存Android HTC中的視頻?
String LocalFilePath = videoUrl.substring(
videoUrl.lastIndexOf("/") + 1, videoUrl.length());
File dire = new File(android.os.Environment.getExternalStorageDirectory(), LocalFilePath);
int bytesread = 0;
byte[] bytes = new byte[8192];
InputStream strm = null;
HttpResponse response = null;
HttpEntity entity = null;
String LocalFile = null;
FileOutputStream foStream;
BufferedOutputStream writer = null;
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
videoUrl = videoUrl.replace(" ", "%20");
HttpGet httpget = new HttpGet(videoUrl);
response = httpclient.execute(httpget);
entity = response.getEntity();
strm = entity.getContent();
LocalFile = android.os.Environment.getExternalStorageDirectory() + LocalFilePath;
//directory = null;
foStream = new FileOutputStream(dire);
writer = new BufferedOutputStream(foStream);
do {
bytesread = strm.read(bytes, 0, bytes.length);
if (bytesread > 0) {
writer.write(bytes, 0, bytesread);
writer.flush();
}
} while (bytesread > 0);
writer.close();
foStream.close();
strm.close();
return;
} catch (Exception e) {
// dire.delete();
e.printStackTrace();
}
你想要保存它?編寫路徑 – iTurki
我想將它保存在我的Android設備gallary中。但是我沒有得到它的正確道路是什麼? –