Java I';我在使用FileInputStream读取属性文件时遇到问题

Java I';我在使用FileInputStream读取属性文件时遇到问题,java,file-io,classpath,Java,File Io,Classpath,我正在开发一个web应用程序,并在com.xx.yy包中创建了一个属性文件。我需要从作者包com.aa.bb中的类中读取此文件 我有以下代码: try { FileInputStream fileInputStream = new FileInputStream("com/xx/yy/myfile.properties"); internationalizationFile = new Properties(); internationalizationFile.load

我正在开发一个web应用程序,并在com.xx.yy包中创建了一个属性文件。我需要从作者包com.aa.bb中的类中读取此文件

我有以下代码:

try {
    FileInputStream fileInputStream = new FileInputStream("com/xx/yy/myfile.properties");
    internationalizationFile = new Properties();
    internationalizationFile.load(fileInputStream);
    fileInputStream.close();
} catch (Exception e) {
    e.printStackTrace();
}

但是它不起作用

您是否尝试通过类加载器加载资源?比如:

    InputStream in = this.getClass().getClassLoader.getResourceAsStream("com/xx/yy/myfile.properties");

您是否尝试通过类加载器加载资源?比如:

    InputStream in = this.getClass().getClassLoader.getResourceAsStream("com/xx/yy/myfile.properties");
1) 我会打印出绝对路径,以确保文件/资源位于正确的位置

2) 我会使用getResourceAsStream,相同的引用。

1)我会打印出绝对路径,以确保文件/资源位于正确的位置

2) 我会使用getResourceAsStream,同样的引用