I am struck in this strange problem .
I am using the following method to download files :
public boolean downloadSection(String link,String fileLocation,long currentlyDownloadedBytes){
try {
RandomAccessFile file = new RandomAccessFile(fileLocation, "rw");
file.seek(currentlyDownloadedBytes+1);
URL imageUrl = new URL(link);
HttpURLConnection conn =(HttpURLConnection)imageUrl.openConnection();
conn.setRequestProperty("Range", "bytes=" + currentlyDownloadedBytes + "-");
conn.setConnectTimeout(100000);
conn.setReadTimeout(100000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
byte buffer[]=new byte[1024];;
while (true) {
// Read from the server into the buffer
int read = is.read(buffer);
if (read == -1) {
break;
}
// Write buffer to file
file.write(buffer, 0, read);
}
file.close();
return true;
} catch (Exception ex){
ex.printStackTrace();
return false;
}
}
When i download mp3 file using this code the downloades file opens up well , But a downloaded android app(.apk file) gives Package Parsing Error on opening and an image never opens up .
Please help Thank you