Java Jar file load resource

Introduction

We can load resource from jar file via URL.

The JAR file URL syntax is

jar:<url>!/{entry}

For example:

jar:http://www.demo2s.com/test.jar!/images/logo.bmp
jar:file:/c:/jarfiles/test.jar!/images/logo.bmp

Assuming that the Test class is in the CLASSPATH:

Class cls = Test.class;
InputStream in = cls.getResourceAsStream("/images/logo.bmp")
URL  url = cls.getResource("/images/logo.bmp");



PreviousNext

Related