Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to download a Zip file  RSS feed

 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So im trying to download a file the url is http://mydomain.com/downloads/test.zip the size is 89
But i get the error
unreported exception java.net.MalformedURLExcption; must be caught or declared to be thrown


My Code

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error you get is pretty self-explanatory. Statements in lines 6 and 7 throw exceptions in some cases (check the API for more details) so they should be try-catch or try-with-resources block.

I would suggest you read Exceptions Lession of of tutorial to get a hint on how to use these properly.
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so like this



get this java.net.MalformedURLException: no protocol: mydomain.com/downloads/test.zip
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are catching IOException, but what about java.net.MalformedURLException?
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:You are catching IOException, but what about java.net.MalformedURLException?


A MalformedURLException IS-A IOException.



James Eman wrote:so like this



get this java.net.MalformedURLException: no protocol: mydomain.com/downloads/test.zip


The error messages pretty much explains it clearly -- an URL protocol is something like ftp, http, https, etc. What protocol did you specify?

Henry
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i need something like this

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!