2

I programmed a simple button that allows the user to open a desired website.

Desktop.getDesktop().browse(new URL(_urlString).toURI());

I want another button that allows the user to open the websites sourcecode directly. I tried the following:

Desktop.getDesktop().browse(new URL("view-source:" + _urlString).toURI());

But I received an "java.net.MalformedURLException: unknown protocol: view-source" exception (I suppose because it doesn't start with http or https). Does anyone know, how to do this in Java?

TheStudent
  • 21
  • 2
  • 1
    If the `MalformedUrlException` contained an error message please add it as it is to your question. Have you tried using `new java.net.URI(_urlString)`? This could circumvent your problem with the malformed url. – SpaceTrucker Aug 23 '22 at 11:10
  • Similar to https://stackoverflow.com/q/51733916/407651 – mzjn Aug 23 '22 at 12:56
  • The exact error is "java.net.MalformedURLException: unknown protocol: view-source" – TheStudent Aug 23 '22 at 15:03
  • Yes, and that is the same error as in the linked question. – mzjn Aug 23 '22 at 15:05

0 Answers0