有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我在使用FileInputStream读取属性文件时遇到问题

我正在开发一个web应用程序,并在com包中创建了一个属性文件。xx。yy。我需要从author package 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();
}

但是它不起作用


共 (2) 个答案

  1. # 2 楼答案

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

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