• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Urgent help required for JEditorPane

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Garry
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
http://ttcplinux.sourceforge.net/java/network.jar,
and in the .jar, you want the file:
com/arpabox/net/Ping.class
The corresponding "jar URL" is:
jar:http://ttcplinux.sourceforge.net/java/network.jar!/com/arpabox/net/Ping.class
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:http://ttcplinux.sourceforge.net/java/network.jar!/com/arpabox/net/index.html");
URLConnection uc = u.openConnection();
InputStream in = uc.getInputStream();
Reader r = new InputStreamReader(in);
int c;
while ((c = r.read()) != -1) {
System.out.print((char)c);
}
}
catch (IOException e) {
system.err.println(e);
}
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the rely.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic