Access a file in package
问题 I am using JUnit to do some automated tests on my application, the tests are in a folder called tests in my JUnit classes package. As of now, I access the files using the following: File file = new File(MyClass.class.getResource("../path/to/tests/" + name).toURI()); Is there a cleaner (and nicer) way to do it? Thanks 回答1: If you want to use the classloader to load your test data, then you can't use File . A File instance represents a path in the file system. The class loads files from the