首页javapropertiesJava Collection - 如何在启动目录中加载属性文件

Java Collection - 如何在启动目录中加载属性文件

我们想知道如何在启动目录中加载属性文件。
  


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

public class Main {

  public static void main(String args[]) throws Exception {
    Properties props = new Properties();

    props = new java.util.Properties();
    String path = new Main().getClass().getProtectionDomain().getCodeSource().getLocation()
        .toString().substring(6);
    FileInputStream fis = new FileInputStream(new File(path + "\\myprops.props"));
    props.load(fis);
    System.out.println(props);

  }
}