• Monday, January 19, 2015

    Java - Very simple HTTP file downloader

    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

    Syed Masoom Rizvi

    Author & Editor

    Hi, This is Syed Masoom Rizvi, who is continue exploring the world of programming ,programming and programming... :)

    0 comments:

    Post a Comment