In play 1.x was possible to use code that can get a file from relative application's path. Like this:
static File xmlDataFile= VirtualFile.fromRelativePath(
"/app/parsers/data/some_data.xml"
).getRealFile();
This code is not controller's code. But some code in app/parsers package.
How can I do the this in playframework 2.x? For Java!
public static Result menu() throws IOException {
String path = Play.application().resource("/resources/menu.json").toString();
String content = Files.toString(new File(path), Charsets.UTF_8);
return ok(content).as("JSON");
}
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.