简体   繁体   中英

Getting Resource as InputStream in Playframework

I have the following Problem in my Play-Application: I placed a file called "logfileSearch.properties" in my conf folder. Then i wanted to get a inputStream with mentioned file in it.

@Inject
Provider<Application> app;

public CustomNodeList newSearch() throws IOException {
    Application application = app.get();
    ClassLoader classLoader = application.classloader();
    InputStream inputStream = classLoader.getResourceAsStream("logfileSearch.properties");
    .....
}

With this Code i got a NullPointerException in the line:

Application application = app.get();

If someone here is able to help me i would be very happy.

More Info:

  • Play version: 2.5.14
  • Scala version: 2.11.11

you can use current class loader as described in Play documentation
like:

   this.getClass().getResourceAsStream("logfileSearch.properties");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM