5

I am trying to load a resource using ClassLoader.getResourceAsStream in a JUnit test in Intellij, and it is not found if the resource is in a subfolder. It is found fine in the root of the test resources folder. I am using the correct replace-dots-with-slash notation.-

This is different from the question asked here because I realized I had added a slash in the beginning of the resource path.

Community
  • 1
  • 1
4thex
  • 1,094
  • 1
  • 9
  • 21
  • Possible duplicate of [IntelliJ can't find classpath test resource](http://stackoverflow.com/questions/25513788/intellij-cant-find-classpath-test-resource) – aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Jan 22 '16 at 14:06
  • 1
    Can you show the test method on question, the resource file and your project structure? You are kind of telling us "I've done everything correct, but it isn't working". If that's the case, you should file an IntelliJ bug. Otherwise, you should include enough information in the question to make it reproducible. :-) PS: I'm accessing files from test resources subfolders in IDEA without problems. – Harald K Jan 22 '16 at 14:25
  • 1
    Thank you @haraldK! Your comment, trying to create a minimal project I could share, and the review from a colleague helped me realize my mistake. I had put a leading slash in front of the resource path. Duh! – 4thex Jan 22 '16 at 19:20

1 Answers1

1

The resource path must not start with a slash.

4thex
  • 1,094
  • 1
  • 9
  • 21