Reputation: 783
I am working on an API which returns me a zip file containing multiple XML files, which i have to parse individually after extracting the zip file.
Here is the link for that(will download the zip-file) :
File root = Environment.getExternalStorageDirectory();
String url= "http://clinicaltrials.gov/ct2/results?term=&recr=&rslt=&type=&cond=&intr=&outc=&lead=&spons=&id=&state1=&cntry1=&state2=&cntry2=&state3=&cntry3=&locn=&gndr=Female&age=0&rcv_s=&rcv_e=&lup_s=&lup_e=xml=true";
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(10000); // timeout 10 secs
conn.connect();
InputStream input = conn.getInputStream();
FileOutputStream fOut = new FileOutputStream(new File(root, "new.zip"));
int byteCount = 0;
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = input.read(buffer)) != -1) {
fOut.write(buffer, 0, bytesRead);
byteCount += bytesRead;
}
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
Problem : New.zip File is getting created in sdcard but it seems nothing is downloading also the file size is 0kb. Is my code proper or I have to use something else to handel zipfiles.
I am extremely sorry the api link is invalid ... it should be
& is required before studtxml..
Thnx every 1 for quick response ..
Upvotes: 1
Views: 1687
Reputation: 109237
There is something wrong either in your .zip file URL or in .zip file size(0 byte size) because if we download this .zip file (From URL given by you) from web browser then also its downloaded with 0 byte size.
Upvotes: 1
Reputation: 8302
Your Url in the code String url=...
is not giving me a zip file.
The link you provided is different
Looks like there's an error: lup_e=xml=true
should be lup_e=studyxml=true
Upvotes: 1