Pankaj I love Open Source technologies and writing about my experience about them is my passion. Follow Author. Comments Henzhi Mkali says:. May 23, at am. Jagdeep says:. May 8, at am. February 21, at pm. Pankaj says:. Nuwanga G. July 25, at pm.
Ravi says:. June 4, at am. Asked 8 years ago. Active 2 years, 8 months ago. Viewed 79k times. Improve this question. Sled JmRag JmRag 1, 6 6 gold badges 16 16 silver badges 49 49 bronze badges.
It's not the same since I don't want to donwload a whole site but a file of it! Thanks though! It is the same.
That question is NOT asking about how to download a whole site. Related Questions. You must be Logged on to comment or reply to a post. Anupam Ghosh. Hi Shubhravrat, Good article. Hope you keep writing more. Regards Anupam. Like 1 Share. Right click and copy the link to share this comment. Shubhravrat Deshpande Blog Post Author. Hi Anupam, Thank you for your feedback! Best regards, Shubhravrat.
Like 0 Share. Link Text. Open link in a new tab. We then need to create an HttpGet or HttpPost object to send the request to the server. The request is created by the following line of code:. The execute request function is applied to the client object and returns with a response from the server. Once the request is sent to the server we need a response object to receive the data sent from the server.
To catch the response from the server we use the HttpResponse class object. The data sent by the server in the form of a message is obtained through the getEntity function. You can also obtain the response code sent by the server through the response object and use it to your specific need. The data to be downloaded is encapsulated within the entity object and can be extracted using the getContent function. The getContent function returns an InputStream object that can be further used with a BufferedInputStreamReader to enhance performance.
Now all you need to do is read from the stream byte by byte and write the contents into a file using the FileOutputStream class. The last thing required to be done is closing all the open resources in order to ensure that the system resources are not overutilized and that there are no memory leaks.
So there you have it - these are the simplest ways to download a file using the basic Java code and other third party libraries. Now that we are done with the basics, you can be as creative as you want and utilize the knowledge to suit your needs. So see you next time with a new set of concepts to help you become a better coder.
We wish you happy coding till then. Free eBook: Git Essentials Check out our hands-on, practical guide to learning Git, with best-practices, industry-accepted standards, and included cheat sheet. Download the eBook.
0コメント