java - playframework 2.0 VirtualFile fromRelativePath 丢失

标签 java playframework playframework-2.0

在 play 1.x 中,可以使用可以从相关应用程序路径获取文件的代码。像这样:

static File xmlDataFile= VirtualFile.fromRelativePath(
            "/app/parsers/data/some_data.xml"
    ).getRealFile();

此代码不是 Controller 的代码。但是 app/parsers 包中的一些代码。

我如何在 playframework 2.x 中执行此操作?对于 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");
}

关于java - playframework 2.0 VirtualFile fromRelativePath 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15592390/

相关文章:

java - 无法使用 hibernate spring mvc 更新表

Java - 同时执行两个相应的for循环

java - SOAPMessage 对象中的信封字段为空

java - 错误 : org. apache.xerces.dom.DeferredTextImpl 无法转换为 org.w3c.dom.Element

scala - 在 Play Framework 2.4.2 中使用 scalates/specs2 测试 HttpErrorHandler

Scala 案例有 22 个字段,但在 Scala 2.11.5 中存在 play-json 问题

loops - Playframework 2 java 在模板中迭代 map

java - 使用 Facebook 应用程序访问 token (URL 中的管道字符)

java - Play + Ebean : Changes to the model + database

scala - 如何使用 Play 2.0 创建自定义 404 页面处理程序?