zoukankan      html  css  js  c++  java
  • java——文件的路径

    public class FileTest {
    public static void main(String[] args) throws Exception {
    
    /**
    * currentThread()返回对当前正在执行的线程的引用 
    * getContextClassLoader()返回该线程的上下文 ClassLoader
    * getResource()查找具有给定名称的资源
    */
    System.out.println(Thread.currentThread().getContextClassLoader()
    .getResource(""));
    /**
    * getClassLoader返回该类的类加载器(ClassLoader)。 
    * ClassLoader.getResource()查找具有给定名称的资源
    //    */
    System.out.println(FileTest.class.getClassLoader().getResource("db_config.properties"));
    
    /*
    * ClassLoader类加载器是负责加载类的对象。 一般策略是将名称转换为某个文件名,然后从文件系统读取该名称的“类文件”。
    * getSystemResource()从用来加载类的搜索路径中查找具有指定名称的资源。
    */
    System.out.println(ClassLoader
    .getSystemResource("db_config.properties"));
    
    //查找带有给定名称的资源。查找与给定类相关的资源的规则是通过定义类的 class loader 实现的。
    System.out.println(FileTest.class.getResource(""));
    
    /*
    * Class.getResource() 查找带有给定名称的资源。查找与给定类相关的资源的规则是通过定义类的 class loader
    * 实现的。 此方法委托给此对象的类加载器。 如果此对象通过引导类加载器加载,则此方法将委托给
    * ClassLoader.getSystemResource(java.lang.String)。 返回:url
    */
    System.out.println(FileTest.class.getResource("/").toString()
    .replace("file:/", "")); // Class文件所在路径
    //getAbsolutePath()返回此抽象路径名的绝对路径名字符串。
    System.out.println(new File("").getAbsolutePath());
    
    System.out.println(System.getProperty("user.dir"));
    }
    }
  • 相关阅读:
    Google-C++编码规范中文版.pdf
    100个gdb小技巧(v1.0).pdf
    NSIS 3.0 发布,Windows 安装程序制作工具
    python爬取各类文档方法归类汇总
    【转】openwrt中ubus
    OpenWrt源码分析之ubus
    详解C语言中的fopen()函数和fdopen()函数
    IPsec技术介绍(转)
    mxml 详解
    Delphi IDE Theme Editor, Delphi IDE 主题编辑器,支持D7~Rad Studio 10.3 RIO及Lazarus
  • 原文地址:https://www.cnblogs.com/rsdqc/p/5479256.html
Copyright © 2011-2022 走看看