1

I want to add html files to jar files and access them through jar in the windows application project how can i access them I am using the following code .

   try{
      File f1= new File(getClass.getResource("/path is the src folder/));
     }

but it is showing no suitable constructor found

adesh
  • 1,157
  • 3
  • 18
  • 28
  • `File` won't take a `URL` as reference. Embedded resources like this aren't actually files, they are `InputStream`s to the resource. Depending on how you're showing them will determine what you need to do. – MadProgrammer Nov 28 '12 at 04:29
  • If your HTML file is inside your JAR, you cannot access it via a `File` object. You would have to use Java's I/O streams' classes to do this. You should provide more information about what it is exactly that you're trying to do. – Isaac Nov 28 '12 at 04:30
  • This will work, `File f1 = new File(new URL(getClass().getResource("/path is the src folder/")));`. This [answer](http://stackoverflow.com/a/9866659/1057230) might can give more inputs on the said topic. – nIcE cOw Nov 28 '12 at 07:49

1 Answers1

3

File won't take a URL as reference. Embedded resources like this aren't actually files, they are InputStreams to the resource.

Depending on how you're showing them will determine what you need to do.

For example, JEditorPane takes a URL via its setPage method

UPDATED

You should be able to load the pages directly into the editor pane using something like...

// editor pane is a reference to a JEditorPane
editorPane.setPage(getClass.getResource("/path is the src folder/"));
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366