commit 254554f962140d302afbe114b4319f49eae437eb Author: xzj <2858617075@qq.com> Date: Thu Oct 17 17:14:59 2024 +0800 fx计算器 diff --git a/lesson06/src/java7131/Profile7131.java b/lesson06/src/java7131/Profile7131.java new file mode 100644 index 0000000..cdcf896 --- /dev/null +++ b/lesson06/src/java7131/Profile7131.java @@ -0,0 +1,34 @@ +package java7131; + +import java.io.InputStream; +import java.util.Properties; + +public class Profile7131 { + + public static void main(String[] args) { + Properties properties = new Properties(); + + try (InputStream input = Profile7131.class.getResourceAsStream("myProFile7131.properties")) { + // 注意:这里假设myProFile7131.properties文件位于资源目录的根下 + if (input == null) { + System.out.println("Sorry, unable to find myProFile7131.properties"); + return; + } + properties.load(input); + } catch (Exception ex) { + ex.printStackTrace(); + return; // 可以在捕获异常后直接返回,避免后续代码执行 + } + + // 获取并输出属性值 + String id = properties.getProperty("id"); + String name = properties.getProperty("name"); + String sex = properties.getProperty("sex"); + String age = properties.getProperty("age"); + + System.out.println("ID: " + id); + System.out.println("Name: " + name); + System.out.println("Sex: " + sex); + System.out.println("Age: " + age); + } +} \ No newline at end of file diff --git a/lesson06/src/java7131/myProFile7131.properties b/lesson06/src/java7131/myProFile7131.properties new file mode 100644 index 0000000..b4f3c73 --- /dev/null +++ b/lesson06/src/java7131/myProFile7131.properties @@ -0,0 +1,4 @@ +id=212207131 +name=\u8C22\u5B50\u5EFA +sex=\u7537 +age=20 \ No newline at end of file