public class ClassLoaderDemo { public static void main(String[] args) throws IOException { // static getSystemClassLoader():获取系统类加载器 ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); // 获取系统类加载器的父类加载器--------》平台类加载器 ClassLoader platformClassLoader = systemClassLoader.getParent(); // 获取平台类加载器的父类加载器--------》启动类加载器 ClassLoader bootstrap = platformClassLoader.getParent(); System.out.println("系统类加载器" + systemClassLoader);// 系统类加载器sun.misc.Launcher$AppClassLoader@4e0e2f2a System.out.println("平台类加载器" + platformClassLoader);// 平台类加载器sun.misc.Launcher$ExtClassLoader@2a139a55 System.out.println("启动类加载器" + bootstrap);// 启动类加载器null // 利用加载器加载指定文件 InputStream is = systemClassLoader.getResourceAsStream("prop.properties"); Properties prop = new Properties(); prop.load(is); System.out.println(prop); is.close(); } }
标签:常用,ClassLoader,System,prop,println,systemClassLoader,方法,加载 From: https://www.cnblogs.com/weiduaini/p/17221705.html