Simple HTTP File Downloader (Full Code provided below)
Full Code:
Copy the above code
- Create a URL object. (Example: URL obj = new URL("http://example.com");)
- Create HttpURLConnection object 'conn'.
- Open the connection of URL object and pass to the conn. (Ex: conn=obj.openConnection();)
- Set requestMethod property of 'conn' to "GET".
- Set setDoOutput property of conn to true.
- Get responseCode of 'conn' to any integer variabe.
- Get fileSize by using getContentLength()
- Create a array variable byte of 1024 byte to get chunk of file from internet.
- Get these chunks continuously and put this in a file.
- Close files and connection.
Full Code:
Copy the above code
No comments:
Post a Comment