时间: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号