dcsimg
need urgent help,can anybody give solution
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   aseem_tiwari
Posted On:   Saturday, June 30, 2001 02:23 AM

i am making an application in which i have to run the html files which are in jar file,without extracting the jar and without using any server.

i can run any simple html file by passing the location as an argument with the command to run browser with the help of batch file but for the html file which is in jar file how can i give the path for html file.

this is the same utility which is given in JBuilder Help section.but i am unable to break it.

can anybody help me!

Re: need urgent help,can anybody give solution

Posted By:   Luigi_Viggiano  
Posted On:   Saturday, June 30, 2001 05:57 AM

I can give you the way to access jar resources as URL; to display the retrieved html in your JavaBrowser will be another issue.


check this code:


import java.net.*;
import java.io.*;

public class JarTest {

URL getJarFileURL(String jarFile, String fileName)
throws MalformedURLException {
return new URL("jar:file:" + jarFile + "!/" + fileName);
}

void printInputStream(InputStream is) throws IOException {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
while (br.ready()) {
System.out.println(br.readLine());
}
br.close();
}

public void displayInMyBroser(URL url) {
// MyJavaBrowser mjb = new MyJavaBrowser();
// mjb.showURL(url);
}

public void displayJarFile(String jarFile, String fileName)
throws MalformedURLException, IOException {
URL u = getJarFileURL(jarFile, fileName);
printInputStream(u.openStream());
// displayInMyBrowser(u);
}

public static void main(String[] args) throws Exception {
String jarFile = "D:/JBuilder4/doc/langspec.jar";
String fileName = "java/langspec/intro.doc.html";
new JarTest().displayJarFile(jarFile, fileName);
}
}
About | Sitemap | Contact