rest - Download zip file using URL in java -


i have below code download file using httpclient url. though program works downloads 3k everytime run it. have setup few proxies overcome corporate network , trying below code automate downloads external website.

the site has few other files(like video, audio well). when try them size 3k. using rest interface files. there need change in code make work still ?

url = "https://samforloogin.com/video.zip";  uri uri = uri.create(url);  defaultproxyrouteplanner routeplanner = new defaultproxyrouteplanner(proxy); closeablehttpclient httpclient = httpclients.custom()                 .setrouteplanner(routeplanner)                 .build(); httpget httpget = new httpget(uri);  httpget.setheader("authorization", "basic " + encoding); closeablehttpresponse response = httpclient.execute(httpget);  java.io.inputstream = response.getentity().getcontent();   string filepath = "c:\\users\\smandodd\\appdata\\local\\temp\\8ee47df6c5a44c9d9c8ff3326d932819\\screenshots.flv"; fileoutputstream fos = new fileoutputstream(new file(filepath ));  int inbyte;  while((inbyte = is.read()) != -1) {     system.out.println("the number of bytes read are" + inbyte);     fos.write(inbyte);  } is.close();  fos.close();  

you can use following code download files in general:

url website = new url("https://samforloogin.com/video.zip"); readablebytechannel rbc = channels.newchannel(website.openstream()); fileoutputstream fos = new fileoutputstream(filepath); fos.getchannel().transferfrom(rbc, 0, long.max_value); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -