Java Reference
In-Depth Information
returned. The default implementation in ClassLoader always
returns null .
public Enumeration<URL> findResources(String name)
Returns an Enumeration of URL objects for all the resources of
the given name. The default implementation in ClassLoader re-
turns an enumeration through zero resources.
Here is a findResource for PlayerLoader :
public java.net.URL findResource(String name) {
File f = fileFor(name);
if (!f.exists())
return null;
try {
return f.toURL();
} catch (java.net.MalformedURLException e) {
return null; // shouldn't happen
}
}
The fileFor method is analogous to the streamFor method of PlayerLoad-
er . It returns a java.io.File object that corresponds to the named re-
source in the file system. If the named file actually exists, then the URL
for the resource is created from the path. (The File class represents a
pathname in the file systemsee " The File Class " on page 543 . )
The BoldPlayer class might come with a BoldPlayer.book that can be found
in the same place as the class file. You can replace this version with your
own by simply placing yours in a location where it will be found first by
the system class loader or the bootstrap loader.
Exercise 16.12 : Modify your results for Exercise 16.11 to allow player
strategies to use attached resources by implementing findResource and
findResources .
 
Search WWH ::




Custom Search