zoukankan      html  css  js  c++  java
  • java之路径问题

    1、this.class.getClassLoader().getResource("路径").getPath();
    路径参数不能以“/”开头,获取classes目录下文件的路径


    2、this.class.getResource("路径").getPath();
    路径参数以“/”开头,则在classes目录下找,不以“/”开头则在当前类的包目录下找


    3、System.getProperty("user.dir")
    获取项目的根路径,在web项目中会因为web容器的不同而不同,在java项目用


    4、getServletContext().getRealPath("路径")
    获取web项目文件的硬盘路径,路径参数以“/”开关
    WebLogic在发布WAR格式的应用时,servletContext.getRealPath的默认返回Null,解决方法
    在web项目的WEB-INF/weblogic.xml文件(需要手动创建)中添加配置
    <container-descriptor>   
      <show-archived-real-path-enabled>true</show-archived-real-path-enabled> 
    </container-descriptor>

  • 相关阅读:
    Go 映射 (map)
    Go 字节 (byte) & 文字符号 (rune)
    Go 数组(array) & 切片(slice)
    Go 字符串 (string)
    Go 变量(var) & 常量(const)
    Go 循环 (for)
    Go 函数
    Go package: strings
    Linux crontab (定时任务)
    Python gc
  • 原文地址:https://www.cnblogs.com/mu-mu/p/3816926.html
Copyright © 2011-2022 走看看