我正在尝试开发一个提供许多电影的应用程序,您可以播放或下载电影。
该应用程序在我有根的Galaxy S4 (Kitkat API:19) 中运行良好,但是当我将它安装在另一台设备上并尝试下载电影时,它给了我异常Java.io.FileNotFoundException
,我不知道是什么问题
这是我的代码
package nmc.net.blue.bluenet_nmc;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
/**
* Created by ElHoni on 5/3/2016.
*/
public class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... aurl) {
int count;
try {
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator + "BlueNet");
if (!folder.exists()) {
folder.mkdirs();
}
String outputPath=folder.getPath()+"/"+aurl[1];
BufferedInputStream input = new BufferedInputStream(url.openStream());
FileOutputStream output = new FileOutputStream(outputPath);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data, 0, 1024)) != -1) {
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
String err = e.toString();
}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.d("ANDRO_ASYNC",progress[0]);
}
@Override
protected void onPostExecute(String unused) {
//Toast.makeText(full_screen_video.this, "", 5);
}
}
顺便说一句,我把这个权限放在manufests
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
请有任何帮助