我的下载视频代码在android 4.0中不起作用
我已经为应用程序编写了视频文件下载代码,它的工作性能达到了2.3.3版本,但是它在android 4.0中无法正常工作,并且出现了类似java.io.FileNotFoundException的错误 有人能帮我解决这个问题吗? 提前谢谢我的下载视频代码在android 4.0中不起作用,android,Android,我已经为应用程序编写了视频文件下载代码,它的工作性能达到了2.3.3版本,但是它在android 4.0中无法正常工作,并且出现了类似java.io.FileNotFoundException的错误 有人能帮我解决这个问题吗? 提前谢谢 public void video_download(String urlstring, String Name) { URL url; try { url = new URL(urlstring); HttpU
public void video_download(String urlstring, String Name) {
URL url;
try {
url = new URL(urlstring);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory()
+ "/application/";
Log.v("PATH", "PATH: " + PATH);
File file = new File(PATH);
file.mkdirs();
String fileName;
fileName = Name + ".mp4";
File outputFile = new File(file, fileName);
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
你确定它没有抛出NetworkOnMainThreadException吗?是的,我确定。现在我得到了更改代码的解决方案,它现在对我来说工作正常好的,亲爱的。你也可以在这里跳过你的答案。并且自己接受它,这样也可以帮助其他开发者。。