52ky

一个概念

src下的文件都属于类下的文件,src是类的根路径

获取路径的方法

String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();

通过这种方式获得的path就是该文件的绝对路径。

注释:
Thread.currentThread():获取当前线程对象
getContextClassLoader():线程对象的方法,可以获取当前线程的类加载器对象
getResource(""):类加载器的方法,可以获取当前类加载器的资源
getPath():获取资源的路径

资源绑定器ResourceBundle获取属性文件

ResourceBundle只适用于xxx.properties属性文件,且该文件必须在类路径下(即ieda中项目的src下),必须是以properties为扩展名的文件

//src下有一个test.properties文件
ResourceBundle bundle = ResourceBundle.getBundle("test");//getBundle()参数一定不带properties扩展名
String s = bundle.getString("className");//这里以键值对获取数据,className为test.properties中的一个键

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2022-01-17
  • 2022-02-07
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2022-01-29
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案