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
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
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); }
" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
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
posted
0
Thanks a lot for the rely.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.