5

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 Answers 2

10

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(...)
Sign up to request clarification or add additional context in comments.

Comments

3

In case you're looking for Play 2.4:

import play.Environment;
...

@Inject
private Environment environment;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.