什么是阅读上的服务器字符串中发挥Framework 2.0中的文本文件的最简单方法(What is

2019-11-02 01:08发布

我找不到VFS或任何其他简单直接的方式来阅读文本文件作为字符串中播放2.0.4。

编辑:我在寻找一个Java解决方案。 遗憾地错过一块信息。

Answer 1:

您可以使用此代码:

String content = Files.toString(new File("files/config.txt"), Charsets.UTF_8);

它是使用谷歌共享,默认包含在播放。



Answer 2:

默认情况下,播放2个进口谷歌共享库,用它和Java的File ,你可以读取任何文件和流的传递到任何地方。 无需VFS了...



Answer 3:

当你在Windows中,传递文件路径时,不要忘了添加两个“\”。 例如:

    File file = new File(""); // to create an empty file 
    // we suppose that the file in the public folder 
    File file_to_read = new File(file.getAbsolutePath() + "\\public\\filename.txt");

祝好运



Answer 4:

您是否在寻找Java或Scala的解决方案?

在Scala中,你可以做这样(没有外部依赖性)从文件中读取

scala.io.Source.fromFile("/path/to/file.txt").getLines

或者从游戏资源

scala.io.Source.fromURL(Play.resource("/resource/file/packaged/with/play.txt").get).getLines



文章来源: What is the easiest way to read a text file on server as string in play framework 2.0