java 普通项目的配置文件

package com.bd;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Test {
    public static void main(String[] args) throws IOException {
//        File file = new File("");
//        String filePath = file.getCanonicalPath();
//        String arcLib = filePath + File.separator + "properties";
//        System.out.println(arcLib);
        String path = "D:\img2\properties";
        FileInputStream in = new FileInputStream(path);
        Properties props = new Properties();
        props.load(in);
        in.close();
//        InputStream
        // 或使用文件输入流(不推荐),假设当前工作目录为bin

//        InputStream in = new FileInputStream("./config.properties");

//        props.load(in);
//        in.close();

        // 读取特定属性
        String key = "lib_path";
        String ip = props.getProperty(key);
        System.out.println(ip);

    }
}
原文地址:https://www.cnblogs.com/wt7018/p/13306531.html