如何在播放框架中从服务器读取文件 [英] how to read a file from server in play framework
问题描述
我有以下文件:
/app/menus/menu1.yml
我想要读取它的内容
$ b -
简短回答:
fileContent = play.vfs.VirtualFile.fromRelativePath(/ app /menus/menu1.yml)contentAsString();
PlayFramework是使用Java语言构建的。 >
在你的代码中,对java API的使用没有任何限制。
所以,如果你知道文件的绝对路径,你的文件可以使用标准的java代码读取:
java .io.File yourFile = new java.io.File(/ path / app / menus / menu1.yml);
java.io.FileReader fr = new java.io.FileReader(yourFile);
//等等
如果您想从您的相对路径访问文件播放应用程序,您可以使用播放VirtualFile类: http: //www.playframework.org/documentation/api/1.1/play/vfs/VirtualFile.html
VirtualFile vf = VirtualFile.fromRelativePath(/ app / menus / menu1.yml);
File realFile = vf.getRealFile();
FileReader fr = new FileReader(realFile);
//等等
I have the following file
/app/menus/menu1.yml
and I'd like to read it's contents
--
short answer:
fileContent = play.vfs.VirtualFile.fromRelativePath("/app/menus/menu1.yml").contentAsString();
PlayFramework is built using the Java language.
In your code, there is no restriction about the usage of the java API. So, your file can be read using the standard java code, if you know the file absolute path:
java.io.File yourFile = new java.io.File("/path/app/menus/menu1.yml");
java.io.FileReader fr = new java.io.FileReader(yourFile);
// etc.
If you want to access a File in a relative path from your Play application, your can use the play "VirtualFile" class: http://www.playframework.org/documentation/api/1.1/play/vfs/VirtualFile.html
VirtualFile vf = VirtualFile.fromRelativePath("/app/menus/menu1.yml");
File realFile = vf.getRealFile();
FileReader fr = new FileReader(realFile);
// etc.
这篇关于如何在播放框架中从服务器读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!