zoukankan      html  css  js  c++  java
  • getResource() 和 getClassLoader().getResource()

    getResource() 和 getClassLoader().getResource()

    getResource()

    /**
     * @Author: CHZ
     * @DateTime: 2020/8/13 23:35
     * @Description: TODO
     * srciopathgetResourcePathTest.java
     */
    public class getResourcePathTest {
        @Test
        public void testGetResource(){
            //获取相对getResourcePathTest包下的a.txt
            //file:/D:/workspace_for_idea/Demo/Test/out/production/Test/io/path/a.txt
            System.out.println(getResourcePathTest.class.getResource("a.txt"));
            
            //获取类加载根目录Source Root
            //file:/D:/workspace_for_idea/Demo/Test/out/production/Test/
            System.out.println(getResourcePathTest.class.getResource("/"));
        }
    }
    

    getClassLoader().getResource()

        @Test
        public void testGetClassLoaderResource(){
            //相对于Source Root
            //file:/D:/workspace_for_idea/Demo/Test/out/production/Test/
            System.out.println(getResourcePathTest.class.getClassLoader().getResource(""));
    
            //file:/D:/workspace_for_idea/Demo/Test/out/production/Test/a.txt
            System.out.println(getResourcePathTest.class.getClassLoader().getResource("a.txt"));
            
            //以 / 开头 返回null
            System.out.println(getResourcePathTest.class.getClassLoader().getResource("/a.txt"));
        }
    
  • 相关阅读:
    sql 计算auc
    tf.app.flags
    transformer
    python 直连 hive
    rnn 详解
    yolov3
    记学习react-native
    html5横、竖屏状态 以及禁止横屏
    图片懒加载
    npm安装的时候报-4048
  • 原文地址:https://www.cnblogs.com/kikochz/p/13499737.html
Copyright © 2011-2022 走看看