1

Currently I am trying to start a download of files from a server with an onclicklistener and I believe I am making progress for the most part but I'm stumped on how to get it to save to external storage. It seems as though no matter what I put as the file location it always tries to download to internal and fails. I have already included WRITE_EXTERNAL_STORAGE permission in my manifest. this is my code for the specific process I am trying.

        public void DownloadFromUrl() {
    try {

        URL url = new URL("http://www.soldier9312-xda.de/svn/leedroid-10/trunk");
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();


        String Path = Environment.getExternalStorageDirectory() + "/Leedroid/SVN";
        Log.v("PortfolioManger", "PATH: " + Path);
        File file = new File(Path);
        file.mkdirs();
        FileOutputStream fos = new FileOutputStream(Path);

        InputStream is = c.getInputStream();

        byte[] buffer = new byte[702];
        int len1 = 0;
        while ((len1 = is.read(buffer)) != -1) {
            fos.write(buffer, 0, len1);
        }
        fos.close();
        is.close();
    } catch (IOException e) {
        Log.d("PortfolioManger", "Error: " + e);
    }
    Log.v("PortfolioManger", "Check: ");
}

0 Answers0