Hi,
by using web services we are able to download file from cloud to buffer storage. We need to now access this downloaded file from buffer memory and move it to SD card. I am using Eclipse and Android plug in.
Can someone share any code ?
My code snippet is below.
String filename = "Test.zip";
URL url = new URL(FromUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
FileOutputStream fileOutput = openFileOutput(filename, Context.MODE_WORLD_READABLE);
InputStream inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
int downloadedSize = 0;
//create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the buffer
//now, read through the input buffer and write the contents to the file
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength;
}
//close the output stream when done
fileOutput.close();
return filename;