5
votes

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?

2

2 Answers

10
votes

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(...)
3
votes

In case you're looking for Play 2.4:

import play.Environment;
...

@Inject
private Environment environment;

...
//usage
environment.getFile("file/path/relative/to/project");