zoukankan      html  css  js  c++  java
  • 反射前序------使用类加载器对peoperties文件的加载

    package com.heima.userJSTL;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    import java.util.Properties;
    
    public class PropretiesDemo {
        public static void main(String[] args) throws Exception {
            //当使用字节流的时候默认的目录是当前模块下(eclipse默认是项目下)
            FileInputStream fis = new FileInputStream("a.properties");
            Properties prop = new Properties();
            prop.load(fis);
            String username = prop.getProperty("username");
            System.out.println(username);
            //当使用类加载器以流的方式加载文件时,默认的目录是当前模块的src下
            ClassLoader classLoader = PropretiesDemo.class.getClassLoader();
            InputStream is = classLoader.getResourceAsStream("b.properties");
            Properties prop2 = new Properties();
            prop2.load(is);
            String property = prop2.getProperty("username");
            System.out.println(property);
    
    
        }
    
    
    }
    迎风少年
  • 相关阅读:
    Find cmd
    splitFile2SmallFile
    IPC-->PIPO
    Thread and shared lock
    Python Thread related
    linux 文件系统
    linux commands
    关于 gnome3 无法显示应用程序所有界面的反馈
    Windows 网络编程
    常见端口 HTTP代码
  • 原文地址:https://www.cnblogs.com/ZYH-coder0927/p/13782130.html
Copyright © 2011-2022 走看看