Does GetResourceAsStream work differently on Mac OSX and Windows 7?

I have a set of unit test cases that depend on the test.properties file. When I run tests on Mac OSX or Linux using Maven ("mvn test"), they work fine. But when working under Windows 7, they cannot find the file unless I copy it directly to the class folder. The code for returning properties is the following two methods:

private void loadProperties() {
    try {
         properties.load(HibernateTestCase.class.getResourceAsStream(getPropertiesFilePath()));
    } catch (Exception ioExc) {
        ioExc.printStackTrace();
    }
}

private String getPropertiesFilePath() {
    return File.separator + "test.properties";
}

What is the real deal here? Is the file path incorrectly set? Thanks in advance!

+3
source share
2 answers

"/". File.separator ( UNIX /, Windows ).

+8

, .

+1

Source: https://habr.com/ru/post/1723835/


All Articles