0

I'm using windows vista and Eclipse for developing. I write the simple code to download a file and store it on my sd card. But i'm getting Exception(File not found exception). Here is my code

 public void downloadNewapk() {
    try {
        URL url = new URL(apkURL.toString());
        HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();

        String PATH = Environment.getExternalStorageDirectory()
                + "/download/";
        Log.v("log_tag", "PATH: " + PATH);
        File file = new File(PATH);
        if (!file.exists()) {
            file.mkdirs();
        }
        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 (IOException e) {
        Log.d("log_tag", "Error: " + e);
    }
    Log.v("log_tag", "Check: ");
}

I have added user permission in manifest.xml And i check for SD card status in Environment.getExternalStorageState() it gives as "removed" But i added 1GB size for my sd card when creating the AVD. I'm new to android and resolving this is really important to me Please anyone can help me

Balaji Khadake
  • 3,449
  • 4
  • 24
  • 38
sam
  • 1
  • 1
    I'd suggest u to remove the emulator and re-create new one. Once it worked for me that way. – Jay Mayu Nov 04 '11 at 06:23
  • I also accounted the same problem a few days ago.But I have not solved it either.If you solve it , plz let me know.:-) – Rocky Nov 15 '11 at 01:22

1 Answers1

0

Check if you have emaulator's sdcard created with permissions to write on it.

Refer: Android Emulator sdcard push error: Read-only file system

After this step, I believe it shall work for you programatically as well.

Community
  • 1
  • 1
Sumit
  • 291
  • 2
  • 2