首页javapropertiesJava Collection - 如何在类路径中加载属性文件

Java Collection - 如何在类路径中加载属性文件

我们想知道如何在类路径中加载属性文件。
  


import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;

public class Main {

  public static void main(String args[]) throws Exception {
    
    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("myprops.props");
    props.load(url.openStream());
    System.out.println(props);

  }
}