【前言】最近笔者,思绪中萦绕着这么一句话“艾欧尼亚在改变”。因此,笔者就在想。艾欧尼亚的世界在改变,为什么自己要一成不变的去应对这个变化的艾欧尼亚。找个借口说:“我是双子座的,我时刻都在改变着”。

一、在src下创建

二、propertites文件内容

三、代码

package com.css.java.learning.massbag;

import java.io.FileInputStream;
import java.util.Properties;
/**
 * java读取propertites配置文件
 * @author Red_Ant 20180926
 */
public class ReadProperty {
	public static void redPropertites() {
		FileInputStream in = null;
		try {
			Properties properties = new Properties();
			in = new FileInputStream(ReadProperty.class.getResource("20180926.properties").getPath());
			properties.load(in);
			StringBuilder sb = new StringBuilder();
			sb.append(properties.getProperty("r"));
			sb.append(properties.getProperty("e"));
			sb.append(properties.getProperty("d"));
			sb.append(properties.getProperty("a"));
			sb.append(properties.getProperty("n"));
			sb.append(properties.getProperty("t"));
			System.out.println("读取配置信息成功!");
			System.err.println(sb);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取配置信息失败!");
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) {
		redPropertites();
	}
}

四、操作结果