日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Java中Properties类的操作

發布時間:2025/7/14 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java中Properties类的操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java中Properties類的操作

?

?

?=============================================

?

?

com.gordon.constant

Constant.java:

package com.gordon.constant;public interface Constant {/*** 根據名稱讀取常量* @param name* @return*/public String get_constant(String name); }

?

SystemConstant4PropImpl.java

package com.gordon.constant;import java.io.IOException; import java.io.InputStream; import java.util.Properties;public class SystemConstant4PropImpl implements Constant {public Properties prop = null;public SystemConstant4PropImpl() {InputStream in = ClassLoader.getSystemResourceAsStream("constant.properties");prop = new Properties();try {prop.load(in);} catch (IOException e) {e.printStackTrace();}}public SystemConstant4PropImpl(String prop_path) {InputStream in = ClassLoader.getSystemResourceAsStream(prop_path);prop = new Properties();try {prop.load(in);} catch (IOException e) {e.printStackTrace();}}/*** 獲取properties文件中的屬性*/@Overridepublic String get_constant(String name) {return prop.getProperty(name);} }

?

SystemConstant4XMLImpl.java

package com.gordon.constant;public class SystemConstant4XMLImpl {}

?

com.grodon.test

TestConstantClass.java:

package com.gordon.test;import org.junit.Test;import com.gordon.constant.SystemConstant4PropImpl;public class TestConstantClass {@Testpublic void run() {try {SystemConstant4PropImpl scp = new SystemConstant4PropImpl();String db_username = scp.get_constant("db.username");System.out.println(db_username);} catch (Exception e) {e.printStackTrace();}} }

?

constant.properties:

db.username=root

?

運行結果:

?

轉載于:https://www.cnblogs.com/hfultrastrong/p/7611536.html

總結

以上是生活随笔為你收集整理的Java中Properties类的操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。