[JAVA] Two ways to read configuration files: ResourceBundle and Properties

Uncle Cthulhu 2022-11-24 21:24:27 阅读数:93

javawaysreadconfigurationfiles

Last code:

package com.construn.vehiclenetty.util;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import java.util.ResourceBundle;/*** Created with IntelliJ IDEA.** @author: zhangenke* @Date: 2018/9/25 on 5:19 PM* @description:*/public class TestUtil {public static void main(String[] args) throws IOException {InputStream is = TestUtil.class.getClassLoader().getResourceAsStream("service.properties");Properties p = new Properties();p.load(is);System.out.println(p);// {zookeeper=localhost:2181, kafka=localhost:9092, message=http://localhost:8083/,// vehicle=http://localhost:8080/}System.out.println(p.get("vehicle"));// http://localhost:8080/ResourceBundle resourceBundle = ResourceBundle. getBundle("service");System.out.println(resourceBundle);// [email protected] vehicle = resourceBundle. getString("vehicle");System.out.println(vehicle);// http://localhost:8080/}}

copyright:author[Uncle Cthulhu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/328/202211242120378434.html