网页设计的网站,网站ftp密码怎么修改,wordpress 农家乐,二维码制作平台当我们有一个使用文本文件存储配置的应用程序且该配置通常为keyvalue格式时#xff0c;我们可以java.util.Properties用来读取该配置文件。这是一个名为的配置文件示例app.config#xff1a;app.nameProperties Sample Codeapp.version1.0下面的代码向您展示了如何读取配置。…当我们有一个使用文本文件存储配置的应用程序且该配置通常为keyvalue格式时我们可以java.util.Properties用来读取该配置文件。这是一个名为的配置文件示例app.configapp.nameProperties Sample Codeapp.version1.0下面的代码向您展示了如何读取配置。package org.nhooo.example.util;import java.io.*;import java.net.URL;import java.util.Objects;import java.util.Properties;public class PropertiesExample {public static void main(String[] args) {Properties prop new Properties();try {// 配置文件名String fileName app.config;ClassLoader classLoader PropertiesExample.class.getClassLoader();// 确保配置文件存在URL res Objects.requireNonNull(classLoader.getResource(fileName),Cant find configuration file app.config);InputStream is new FileInputStream(res.getFile());// 加载属性文件prop.load(is);// 获取app.name键的值System.out.println(prop.getProperty(app.name));// 获取app.version键的值System.out.println(prop.getProperty(app.version));// 获取app.vendor键的值以及// 密钥不可用返回Kode Java as// 默认值System.out.println(prop.getProperty(app.vendor,Kode Java));} catch (IOException e) {e.printStackTrace();}}}该代码段将打印以下结果Properties Sample Code1.0Kode Java