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