Lasitha Yapa Lasitha Yapa - 1 year ago 101
Java Question

What is the alternative for Play.application()

I am new to Play framework. I wanted to read a file which is in the conf folder. So I used


But I got to know that play.Play is deprecated now. What can I use to read the file.
I read this article and can hardly understand what it says.

Answer Source

Just inject the Application in the class where you need it. Supposing it is in a controller:

import play.Application;
import javax.inject.Inject;
import javax.inject.Provider;

class YourController extends Controller {

    Provider<Application> app;

    public Result someMethod() {
        // (...)
        // File is placed in conf/Data.json
        InputStrem is = app.get().classloader().getResourceAsStream("Data.json");
        String json = new BufferedReader(new InputStreamReader(is))
        return ok(json).as("application/json");    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download