java - 找不到我的 file.properties

标签 java file properties call

我尝试了很多想法来找到失败的地方,但我不知道该怎么做。我的代码是:

    //DominioLlamadaRedSys.java

    Properties d = new Properties();
    InputStream entrada = null;
    try {


        entrada = new FileInputStream("prop/datosApp.properties");
        d.load(entrada);

        System.out.println(d.getProperty("TXD.endPointUrl")); 

    } catch (IOException ex) {

        System.out.println("ERROR: "+ ex.getMessage());

    } finally {
        if (entrada != null) {
        try {
            entrada.close();
        } catch (IOException e) {
        }
        }
    }

我在“com.rsi.secpay.dominio”中的一个类中调用该文件,这总是捕获相同的异常(找不到该文件),我尝试退出“prop/”(只是“datosApp.属性”),属性文件如下:

enter image description here

最佳答案

如果您的 prop 包位于类路径中,您可以使用类加载器获取流:

InputStream is = DominioLlamadaRedSys.class.getResourceAsStream("/prop/datosApp.properties");

关于java - 找不到我的 file.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31407028/

相关文章:

java - Java 中排序和交换元素的最快方法

java - 泰语字符显示??????在jsp中标记文件上传

java - 无法让android创建通知

java - 如何将 org.apache.tika 源集成到我的项目中?

java - 黑莓读取项目中的本地属性文件

java - Spring : PropertyPlaceholderConfigurer cannot find property file

java - 文件已存在时尝试启动程序时出现异常

Python:从一个文件中选择一系列行并将其复制到另一个文件

delphi - 作为属性的类引用

c++ - C++ 中的类属性变量