Reputation: 196
Sirs,
I am developing a GUI in Java with Netbeans.
For the purposes of prototyping, I am needing to open an HTML document (that is located on my hard drive) into a jEditorPane. The code that I currently have is this:
HtmlPane.setPage(new URL("C:\\Users\\blah\\Desktop\\example1\\example1\\PracticeHTML.html"));
This throws a java.net.MalformedURLException
.
When I try:
HtmlPane.setPage(new URL("https://www.example.com"));
The example.com page opens as one would expect in my HtmlPane.
Obviously, anything beginning with C:\\Users . . .
isn't a bona fide URL in that the computer never has to get on the world wide web to get to the html document, but I fail to see why this throws an exception.
Can anyone tell me where I have gone wrong?
Thanks in advance.
Upvotes: 0
Views: 196
Reputation: 3494
The issue is that a file path in itself is not a url. To specify a local file as a url you need to do something like this:
file:///[path]
The full syntax is
file://[host]/[path]
... but host
is assumed to be localhost
if missing.
Upvotes: 1