import java.io.*; import java.net.*; public class A{ public static void main(String args[]){ A a=new A(); a.download_zip_file("c:/","https://sites.google.com/site/ansisliit/Home/Test.zip"); System.out.println("Downloaded!"); } public void download_zip_file(String save_to,String from) { try { URL url=new URL(from); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("content-type", "binary/data"); InputStream in = conn.getInputStream(); FileOutputStream out = new FileOutputStream(save_to + "tmp.zip"); byte[] b = new byte[1024]; int count; while ((count = in.read(b)) >= 0) { out.write(b, 0, count); } out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } }
Saturday, December 17, 2011
Download Binary File From The Internet
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment