0

I need to get inputStream from ./resources but I got all the time NULL. Let me show you, what I did.

This is my simple code:

private const val CREDENTIALS_FILE_PATH = "/credentials.json"
val inputStream = javaClass.getResource(CREDENTIALS_FILE_PATH)

When I set debugger on inputStream, I got null all the time.

debugger

I tried write input in different way, but it also do not work.

val inputStream = this::class.java.classLoader.getResource(CREDENTIALS_FILE_PATH)
val inputStream = javaClass.classLoader.getResource(CREDENTIALS_FILE_PATH)

So I did something like that:

val inputStream = javaClass.getResource(".")

and I think there is problem, because this path refer to ./out/test/classes not to ./out/test/resources debuger2

Can I ask for some advice so that I can point to the file from ./resources?

BElluu
  • 381
  • 5
  • 14
  • Could you try the following? `javaClass.classLoader.getResource("credentials.json")`, i.e. using the classLoader and a ~ relative path. – Roland Feb 25 '20 at 14:20
  • I tried it, but it doesn't work that way either – BElluu Feb 25 '20 at 16:03
  • Are you using Gradle, Maven, or something like that? You may want to check what Intellij has set as classpath. Maybe also helpful: https://stackoverflow.com/a/10723585/6202869 or the comments of the answer... – Roland Feb 25 '20 at 16:48
  • I added **.json** to resources patterns in settings of IDE, but still do not work – BElluu Feb 25 '20 at 18:11
  • Maven, Gradle, other? Java version? – Roland Feb 26 '20 at 07:50
  • If you're using the IDE to debug your application make sure you mark the resources directory https://imgur.com/a/vtGoFiR – Muli Yulzary Feb 26 '20 at 10:09
  • I using JDK 12 and Gradle in this project. I had set resources directory. – BElluu Feb 26 '20 at 12:57

0 Answers0