//几种获取配置文件路径的方法
   InputStream inputStream1 = TestFile.class.getClassLoader().getResourceAsStream("db.properties");

  // TestFile是类名  

  InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("db.properties");

   //获取配置文件的绝对路径(硬盘上的路径)
   URL url1=Thread.currentThread().getContextClassLoader().getResource("db.properties");
   String temp=url1.getFile();

---------------------------------------------------------------------------------------------------------------

//在磁盘中  文件夹   和  文件都不存在的情况下可以进行创建 

 File file=new File("F:\\afile\\a.txt");

  file.getParentFile().mkdirs();
    if(!file.exists()){
     file.createNewFile();
    }

--------------------------------------------------------------------------------------------------------------

//如何获取webRoot中文件的路径

String path = this.getClass().getResource("/")+"":

 

 

相关文章:

  • 2021-04-19
  • 2021-10-19
  • 2021-10-22
  • 2021-06-21
  • 2021-08-31
  • 2022-01-18
  • 2021-12-04
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2021-12-14
  • 2021-05-18
  • 2021-06-04
  • 2021-08-06
  • 2021-05-12
相关资源
相似解决方案