File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Urgent help required for JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Urgent help required for JEditorPane" Watch "Urgent help required for JEditorPane" New topic

Urgent help required for JEditorPane

Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Pls help me regarding how i can show a html file within a jeditorpane. The application is packaged as a jar file and the html file is stored in a directory name htmlfiles under the jar.
I am having trouble doing that as it is used as a help system for the application. I think that the problem lies in the url stuff. What url should i give for a html file within the jar file.
Any help will be greatly appreciated.
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
Your instinct is GREAT!
The problem lies in the URL.
First, there is JarURLConnettion:
pubic abstract class JarURLConnection extends URLConnection // Java 1.2
Second, we need a "jar URL", which is constructed in the following way:
suppose you have a URL:,
and in the .jar, you want the file:
The corresponding "jar URL" is:
Get it??
Another example:
URL: ftp:///D%7d/java/network.jar
file: com/arpabox/net/Ping.class
Jar URL: jar:ftp://D%7d/java/network.jar!/com/arpabox/net/Ping.class
So, here, you now how to construct the "Jar URL".
Then, use it to read the html file as follows:
try {
URL u = new URL("jar:!/com/arpabox/net/index.html");
URLConnection uc = u.openConnection();
InputStream in = uc.getInputStream();
Reader r = new InputStreamReader(in);
int c;
while ((c = != -1) {
catch (IOException e) {

" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
In fact, JarURLConnection has a lot of methods which you may find in the API.
You can construct like this:
URL u = new URL("a jar URL goes here");
JarURLConnection juc = u.openConnection();
Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Thanks a lot for the rely.
I agree. Here's the link:
subject: Urgent help required for JEditorPane
It's not a secret anymore!