Documentation

The Java™ Tutorials
Hide TOC
Retrieving Resources检索资源
Trail: Deployment
Lesson: Java Web Start
Section: Developing a Java Web Start Application

Retrieving Resources检索资源

Use the getResource method to read resources from a JAR file. 使用getResource方法从JAR文件中读取资源。For example, the following code retrieves images from a JAR file.例如,下面的代码从JAR文件中检索图像。

// Get current classloader
ClassLoader cl = this.getClass().getClassLoader();
// Create icons
Icon saveIcon  = new ImageIcon(cl.getResource("images/save.gif"));
Icon cutIcon   = new ImageIcon(cl.getResource("images/cut.gif"));

The example assumes that the following entries exist in the application's JAR file:该示例假设应用程序的JAR文件中存在以下条目:


Previous page: Developing a Java Web Start Application
Next page: Deploying a Java Web Start Application