Reading from static resource file

Marco Bungart m.bungart at
Thu Feb 14 09:32:18 UTC 2019


Please excuse me if you got this eMail twice. I sent it yesterday via
graalvm-users at, but did not receive any answer soo... I
decided to send it out via graal-dev :)

I have a problem with resource files when building native images. I
would like to read the content of a resource file. The snippet of code
accessing the file is:

    String PATH = "/wordCount/le_grand_cyrus.txt";
    try (
      BufferedInputStream is =

      BufferedReader reader = new BufferedReader(new
InputStreamReader(is))) {
      System.out.println(is.available()); // Exception occurs here

running the program on the JVM works just fine.

When I, however, compile the jdk to an native image, the program
terminates with

    Exception in thread "main" Stream closed

I compiled the native image with -H:IncludeResources='...'
-H:Log=registerResources to verify that the files are included in the
native image.

Am I doing something wrong or is this a known issues? Any help is much
appreciated :)

Thanks in advance,
Marco Bungart

More information about the graal-dev mailing list