Hi,
I have spent hours searching for tutorials on downloading a file to a folder
on my phone. Despite my best efforts I still haven't been able to
accomplish this task.
Here is what I have so far. It is within a on button click handler, I will
place the code in a separate class when I get it working.
try {
URL url = new URL("http://mywebsite.com/cards/1.jpg");
File file = new File("/sdcard/cards/1.jpg"); // I dont think this is right!
example I got this code from used /data/data/<project name>/<filename> but
did not work
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
bis.close();
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.flush();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Many Thanks in advance for any assistance.
Mark
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en