![]() If you call getResourceAsStream() method on an object which is loaded by BootStrap ClassLoader then it will delegate it to ClassLoader.getSystemResourceAsStream() method. ![]() Internally this method delegates the loading request of resource to its class loader. If you are creating J2ME games or applications, you can use these methods to load icons and tiles for your game, and all other resources for your application as well. These methods are available from JDK 1.1 and you can even use them anywhere you have access to the core Java library. class with the name of any class like Sample.class will give you a reference of. If you have an object, then you can call getClass() because it's a non-static method, on the other hand, if you don't have an object, you can simply use. You can obtain a reference of Class by calling either getClass() method or by using class literal. ![]() These methods accept the path of resource as String and return URL and InputStream respectively. Suppose, you have a properties file inside the config folder of your project, and you want to load that properties file, how do you do that? Similarly, you have icons and thumbnails for your web applications on the icons directory of your project, how do you load them? The answer is by using ' getResource() and getResourceAsStream() method. Java provides API to read these resources as InputStream or URL. properties files, images, icons, thumbnails, or any binary content. class files, but also can be used to load resources e.g. Classpath in Java is not only used to load.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |