--
How to accessing a resource within a jar file? You access some resources (images, xml file or properties file) that are inside a jar. For example, you can retrieve an image with the following way:
InputStream in = this.getClass().getClassLoader()
.getResourceAsStream("com/linar/java2com/plus.gif");
int c;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while ((c = in.read()) != -1) {
byteArrayOutputStream.write((char) c);
}
Here is another example using the getResource() method that takes an URL parameter to retrieve an image:
URL url = this.getClass().getClassLoader()
.getResource("com/linar/java2com/plus.gif");
ImageIcon image = (new ImageIcon(url));
How to accessing a resource within a jar file? You access some resources (images, xml file or properties file) that are inside a jar. For example, you can retrieve an image with the following way:
InputStream in = this.getClass().getClassLoader()
.getResourceAsStream("com/linar/java2com/plus.gif");
int c;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while ((c = in.read()) != -1) {
byteArrayOutputStream.write((char) c);
}
Here is another example using the getResource() method that takes an URL parameter to retrieve an image:
URL url = this.getClass().getClassLoader()
.getResource("com/linar/java2com/plus.gif");
ImageIcon image = (new ImageIcon(url));
Comments
Post a Comment