image.png

在使用 Properties 类之前

以读取配置文件信息为例,下面是一个简单的 demo

  1. import java.io.*;
  2. public class Main {
  3. public static void main(String[] args) throws Exception {
  4. String path = "./mysql.properties";
  5. BufferedReader br = new BufferedReader(new FileReader(path));
  6. String line = null;
  7. while ((line = br.readLine()) != null) {
  8. String[] split = line.split("=");
  9. System.out.println(split[0] + " 的值是:" + split[1]);
  10. }
  11. br.close();
  12. }
  13. }