首页 > 数码科技 > 正文内容

java如何用命令读取properties文件

时间:2025-04-26 21:00:38

如何读取Java中properties文件的数据

写个例子试试

test.properties文件 (尝试读取该文件的内容)

读取test.properties文件数据的代码

import java . io . IOException ; import java . io . InputStream ; import java . util . Properties ; public class test { public static void main ( String [ ] args ) throws IOException { InputStream inputStream = test . class . getClassLoader ( ) . getResourceAsStream ( "test.properties" ) ; Properties properties = new Properties ( ) ; properties . load ( inputStream ) ; System . out . println ( "userName=" + properties . getProperty ( "userName" ) ) ; System . out . println ( "password=" + properties . getProperty ( "password" ) ) ; System . out . println ( "The content of properties is " + properties ) ; inputStream . close ( ) ; } }

版权声明:转载此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益, 请作者持权属证明与本网联系,我们将及时更正、删除,谢谢您的支持与理解。
标签:数码科技

快测评广州东远堂信息科技有限公司版权所有 网站地图提供支持 粤ICP备15011623号