1

I have done video file download code for the application and its working perfact for the version upto 2.3.3 but it does not working properly in the android 4.0 and it is giving the error like java.io.FileNotFoundException Can anyone help me to solve this problem? Thanks in advance

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();
    }
}

0 Answers0