Demo07_Properties.java 827 B

12345678910111213141516171819202122232425262728293031
  1. package J20250728;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.Properties;
  6. import java.util.Set;
  7. /**
  8. * @author WanJl
  9. * @version 1.0
  10. * @title Demo07_Properties
  11. * @description
  12. * @create 2025/7/28
  13. */
  14. public class Demo07_Properties {
  15. public static void main(String[] args) throws IOException {
  16. //创建集合
  17. Properties prop=new Properties();
  18. //创建字符输入流
  19. FileReader fr=new FileReader("myfile.properties");
  20. //加载文件中的键值对属性列表
  21. prop.load(fr);
  22. //遍历集合
  23. Set<String> names = prop.stringPropertyNames();
  24. for (String key : names){
  25. String value = prop.getProperty(key);
  26. System.out.println(key+"==>"+value);
  27. }
  28. }
  29. }