| Use | Cramfull |
| Recipe | Old Netscape |
| Tips | Links |
| Gotchas |
Class.getResource is similar, giving you the URL of the resource instead of an InputStream to read it. Note that getResource is an instance method. Class.getResource makes these changes to the resource name: if the resource name starts with /, it is unchanged; otherwise, the package name is prepended to the resource name after converting . to /. This allows you to use either dots or slashes to separate the components of the name. So normally your resource member name includes the package name, but you don’t specify the package name to getResource. Alternatively, but not recommended, you can specify the fully qualified name of the resource by using a lead / on the name you feed to getResource. Never use \ in resource names. So you can access by either: /com/mindprod/entities/entitytable.ser or the short form entitytable.ser. The short form only works from classes in the com.mindprod.entities package.
// accessing a resource with getResource to give you its URL URL url = Entities.class.getResource( "entitytable.ser" ); System.out.println( url ); // Note that getResource is an instance method of Class, // so You CANNOT say: URL url = Class.getResource( "entitytable.ser" );Note the lack of dots, slashes, package name or class name in the resource.
|
|
available on the web at: |
http://mindprod.com/jgloss/resource.html |
optional Replicator mirror
|
J:\mindprod\jgloss\resource.html | |
![]() |
Please email your
feedback for publication,
letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear
wording, broken/redirected link reports, suggestions to improve this page or comments to
Roedy Green :
| |
| Blog | Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[23.22.252.150] |
|
| Feedback | You are visitor number 25,513. | |