当前位置: 技术问答>java相关
请问:InputStream is =getClass().getResourceAsStream("/db.properties")中,getResourceAsStream 是什么意思,文件db.properties应该
来源: 互联网 发布时间:2015-05-20
本文导语: 请问:InputStream is =getClass().getResourceAsStream("/db.properties")中,getResourceAsStream 是什么意思,文件db.properties应该放在哪里,为什么is返回值为空? | public InputStream getResourceAsStream(String name)Finds...
请问:InputStream is =getClass().getResourceAsStream("/db.properties")中,getResourceAsStream 是什么意思,文件db.properties应该放在哪里,为什么is返回值为空?
|
public InputStream getResourceAsStream(String name)Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.
This method delegates the call to its class loader, after making 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 "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream.
This method delegates the call to its class loader, after making 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 "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream.
|
方法getResourceAsStream()是一个标准方法,用来打开一个外部输入文件。文件的位置取决于类加载器,而标准的类加载器从classpath开始搜索。