`
lgstarzkhl
  • 浏览: 328997 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

class.getClassLoader().getResources

    博客分类:
  • java
阅读更多
this.getClass().getClassLoader().getResource("template");
   首先,调用对象的getClass()方法是获得对象当前的类类型,这部分数据存在方法区中,而后在类类型上调用getClassLoader()方法是得到当前类型的类加载器,我们知道在Java中所有的类都是通过加载器加载到虚拟机中的,而且类加载器之间存在父子关系,就是子知道父,父不知道子,这样不同的子加载的类型之间是无法访问的(虽然它们都被放在方法区中),所以在这里通过当前类的加载器来加载资源也就是保证是和类类型同一个加载器加载的。
分享到:
评论

相关推荐

    SpringMVC源码分析系列

    NULL 博文链接:https://zzc1684.iteye.com/blog/2210510

    Mybatis源码分析.md

    InputStream inputStream = CommonTest.class.getClassLoader().getResourceAsStream("mybatis-configuration.xml"); SQLSessionFactory SQLSessionFactory = new SQLSessionFactoryBuilder().build(inputStream)...

    pull解析XML

    List<WeatherInfos> infos = weatherService.getWeatherInfos(MainActivity.class.getClassLoader().getResourceAsStream("z.xml")); StringBuffer sb = new StringBuffer(); for(WeatherInfos info : infos){ ...

    传智博客jdbc学习案例

    InputStream inStream = DaoFactory.class.getClassLoader() .getResourceAsStream("daoconfig.properties"); prop.load(inStream); String userDaoClass = prop.getProperty("userDaoClass"); ...

    TangHanF#project_record_book#获取jar包所在路径1

    //得到windows下的正确路径// String path = monitorClientMain.class.getClassLoader().toStr

    sax解析util

    URL url = Configuration.class.getClassLoader().getResource(filename); String str = url.getFile(); // 转换编码 str = URLDecoder.decode(str, "utf-8"); File conf = new File(str); ...

    java读取配置文件的实例代码

    java项目读取配置文件的实例代码,使用class.getClassLoader().getResourceAsStream方法。

    Jonny023#Study#Java-加载properties文件1

    1、使用class变量的getResourceAsStream()方法 2、使用class.getClassLoader()所得到的java.lang.Clas

    Java 高级特性.doc

    //System.out.println(ProxyTest.class.getClassLoader().getParent().getClass().getName()); System.out.println(ProxyTest.class.getClassLoader().getClass().getName()); //test1(); //test2(); } ...

    Digester解析xml

    Digester digester = DigesterLoader.createDigester(TestDigester.class.getClassLoader().getResource(Constants.CONFIG_MAPPINGRULE_PATH)); digester.setValidating(false);

    Java路径问题解决方案汇集

     URLTest.class.getClassLoader().getResource().getPath();  Thread.currentThread().getContextClassLoader().getResource().getPath();等多种相似方式获得的路径,不能被FileReader()和FileWriter()直接应用...

    Java连接数据库代码

    in = MyTask.class.getClassLoader().getResourceAsStream("db.properties"); prop.load(in); this.sql_ip=prop.getProperty("DB_IP").trim(); this.sql_db_name=prop.getProperty("DB_NAME").trim(); this.sql...

    Java ClassLoader学习总结

    主要内容包括 Java类加载机制及加载流程,以及如何定义自己的类加载器,如何实现类的热替换。

    java工厂系列设计模式源码与文档

    Document document = sb.build(this.getClass().getClassLoader().getResourceAsStream(fileName)); Element root = document.getRootElement(); List list = XPath.selectNodes(root, "/beans/bean"); for...

    测试 test-spring-spi

    List<Say> loadFactories = SpringFactoriesLoader.loadFactories(Say.class, TestCase.class.getClassLoader()); for (int i = 0; i < loadFactories.size(); i++) { Say say = loadFactories.get(i); ...

    java自定义弹窗Demo

    Icon icon = new ImageIcon(ConfirmDialog.class.getClassLoader().getResource("info.png")); ScaleIcon scaleIcon = new ScaleIcon(icon); JLabel iconLabel = new JLabel(scaleIcon); iconLabel....

    commons-dbcp2-2.0-bin.zip

    InputStream inStream = DBCPConnection.class.getClassLoader().getResourceAsStream("dbcp.properties"); propreties.load(inStream); DataSource dataSource = BasicDataSourceFactory.createDataSource...

    调用webservice例子 查询手机号归属地 soap协议的传xml

    InputStream inStream = this.getClass().getClassLoader().getResourceAsStream("mobilesoap.xml"); try { addressView.setText(MobileInfoService.getMobileAddress(inStream, mobile)); } catch...

    DruidUtils.java

    p.load(DruidUtils.class.getClassLoader().getResourceAsStream("druid.properties")); ds = DruidDataSourceFactory.createDataSource(p); } catch (Exception e) { e.printStackTrace(); } }

    properties资源文件utils类

    String filepath = ContentMessage.class.getClassLoader().getResource("") .getPath(); filepath = filepath.substring(0, filepath.length() - 8); filepath = filepath + "resource/Application...

Global site tag (gtag.js) - Google Analytics