I am downloading the zip file from my android app. Activity is getting stopped when click on Download button. the following is the code for downloading the zip file.
Download Code:
public void myDownload(View v) {
URL url;
try {
url = new URL("https://github.com/jquery/jquery/archive/master.zip");
try {
InputStream in = url.openStream();
FileOutputStream fos = new FileOutputStream(new File("Master.zip"));
System.out.println("Reading the file.");
int length = -1;
byte[] buffer = new byte[1024];// buffer for portion of data from
// connection
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
System.out.println("File Downloaded");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Thanks for any help!