相关疑难解决方法(0)

getResourceAsStream()返回null.属性文件未加载

我正在尝试加载属性文件.这是我的结构

目录结构

现在我正在尝试加载test.properties文件.但是我变得无效了.我在这里怎么样

public class Test {

    String workingDir = System.getProperty("user.dir");
    System.out.println("Current working directory : " + workingDir);

    File temp = new File(workingDir + "\\" + "test.properties");
    String absolutePath = temp.getAbsolutePath();
    System.out.println("File path : " + absolutePath);

    Properties properties = null;

    try {
        properties = new Properties();
        InputStream resourceAsStream =  Test.class.getClassLoader().getResourceAsStream(absolutePath);
        if (resourceAsStream != null) {
            properties.load(resourceAsStream);
        }


    } catch (IOException e) {
        e.printStackTrace();
    }

    System.exit(0);

} //end of class Test
Run Code Online (Sandbox Code Playgroud)

这个程序打印

Current working directory : D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration …
Run Code Online (Sandbox Code Playgroud)

java

20
推荐指数
3
解决办法
6万
查看次数

标签 统计

java ×1