[solved][Java] Displaying a local html file

Posted By: Xarthor

[solved][Java] Displaying a local html file - 05/28/10 14:00

Good day!

I got a "fast" question about a problem I'm currently unable to solve:
I'd like to display a html file in a Java application.
Displaying a html file from an url (such as http://www.google.com) works, but my html file is a local one.
Its locate in the project's subfolder "Manual".

Which "url" do I pass to the JEditorPane's setPage method to display the index.html file (Manual/index.html) ?

Any help is appreciated!
Thanks in advance!

edit:
Solution: (Thanks to damocles!)
Code:
String manualFile = "file://";
java.io.File currentDir = new java.io.File("Manual/index.html");
manualFile += currentDir.getAbsolutePath();


Posted By: Joey

Re: [Java] Displaying a local html file - 05/28/10 14:04

does the "file:///c:/..."-protocol work (instead of "http://...")?
Posted By: Xarthor

Re: [Java] Displaying a local html file - 05/28/10 14:09

@Joey: I guess it should but I'd rather like to pass a relativ path because the location of the application may change.
Posted By: Helghast

Re: [Java] Displaying a local html file - 05/28/10 14:55

According to Google, passing this shoud work:

Code:
file:///Manual/index.html


Posted By: Xarthor

Re: [Java] Displaying a local html file - 05/28/10 15:06

Quote:

java.io.FileNotFoundException: /Manual/index.html (No such file or directory)


I'm sorry Helghast, it doesn't work. But thanks for the suggestion!
Posted By: Joey

Re: [Java] Displaying a local html file - 05/28/10 18:23

yeah, well, you have to use the absolute path, that's why my sample starts with c:/
Posted By: Quad

Re: [Java] Displaying a local html file - 05/28/10 19:05

isn't tehre a function in java that let's you get the program path?
Posted By: Damocles_

Re: [Java] Displaying a local html file - 05/28/10 21:03

try this one:

java.io.File currentDir = new java.io.File("");
System.out.println(currentDir.getAbsolutePath());
Posted By: Xarthor

Re: [Java] Displaying a local html file - 05/29/10 08:03

Thanks a lot Damocles!
That worked great!

I used this snippet:
Code:
String manualFile = "file://";
java.io.File currentDir = new java.io.File("Manual/index.html");
manualFile += currentDir.getAbsolutePath();


Posted By: Damocles_

Re: [Java] Displaying a local html file - 05/30/10 13:32

cool, no problem
© 2024 lite-C Forums