Hi,
I'm starting on Java and Android and following a few tutorials I can't see
the reason why a file is not being saved
if I'm correct the file should be saved under /data/data/package/ right?
Any idea why
URL u = new URL(aurl);
Log.d("PIC SIZE"," / " + aurl);
int bufferLength = 128;
try {
URLConnection uc = u.openConnection();
String ct = uc.getContentType();
int contentLength = uc.getContentLength();
if (ct.startsWith("text/") || contentLength == -1) {
System.err.println("This is not a binary file.");
return;
}
InputStream stream = uc.getInputStream();
byte[] buffer = new byte[contentLength];
int bytesread = 0;
int offset = 0;
while (bytesread >= 0) {
bytesread = stream.read(buffer, offset,
bufferLength);
if (bytesread == -1)
break;
offset += bytesread;
}
if (offset != contentLength) {
System.err.println("Error: Only read " + offset + "
bytes");
System.err.println("Expected " + contentLength + "
bytes");
}
String theFile = u.getFile();
theFile = theFile.substring(theFile.lastIndexOf('/') +
1);
FileOutputStream fout2 = null;
//fout2 = openFileOutput("asdasd", 0);
FileOutputStream fout = new
FileOutputStream("/sdcard/" + theFile);
fout.write(buffer);
fout.flush();
fout.close();
} catch (Exception e) {
System.err.println(e);
}
In the log I get
ArrayIndexOutofBounds Exception...
Any idea?
Thanks
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---