Search code examples
javaplayframework-2.2

Get File using relative path play framework 2.2 java


I'm trying the following to create a File:

java.io.File myFile = play.Application.getFile("/public/myFiles/myFile.txt");

which is causing the error:

non-static method getFile(java.lang.String) cannot be referenced from a static context

how do use the getFile method to return what I want?


Solution

  • getFile isn't a static method so you need to reference it from an instance of Application.

    This should work to get you the current Application instance:

    Play.application().getFile(...)