Full width home advertisement

Post Page Advertisement [Top]

Simple HTTP File Downloader (Full Code provided below)

  1. Create a URL object. (Example: URL obj = new URL("http://example.com");)
  2. Create HttpURLConnection object 'conn'.
  3. Open the connection of URL object and pass to the conn. (Ex: conn=obj.openConnection();)
  4. Set requestMethod property of 'conn' to "GET".

  5. Set setDoOutput property of conn to true.
  6. Get responseCode of 'conn' to any integer variabe.
  7. Get fileSize by using getContentLength()
  8. Create a array variable byte of 1024 byte to get chunk of file from internet.
  9. Get these chunks continuously and put this in a file.
  10. Close files and connection. 

Full Code:


Copy the above code

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib