FileDocCategorySizeDatePackage
GetResourceDemo.javaAPI DocExample981Fri Apr 20 21:24:48 BST 2001None

GetResourceDemo

public class GetResourceDemo extends Object
Show using classLoader.getResource() to load a file. This is required under Java Web Start.

Fields Summary
Constructors Summary
Methods Summary
public voiddemo()
The demo itself

		// Find the ClassLoader that loaded us.
		// Regard it as the One True Classloader for this app.
		ClassLoader loader = this.getClass().getClassLoader();

		// Use the loader's getResource() method to open the file.
		InputStream is = loader.getResourceAsStream("widgets.properties");
		if (is == null) {
			System.err.println("Can't load properties file");
			return;
		}

		// Create a Properties object
		Properties p = new Properties();

		// Load the properties file into the Properties object
		try {
			p.load(is);
		} catch (IOException ex) {
			System.err.println("Load failed: " + ex);
			return;
		}

		// List it to confirm that we loaded it.
		p.list(System.out);
	
public static voidmain(java.lang.String[] args)

		new GetResourceDemo().demo();