How to get Real path of the app in the play
like this in servlet use:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Strin开发者_运维技巧g filePath = config.getServletContext().getRealPath("/");
}
How to getRealPath in the play ?
Play is all about being easy, right ? so let's keep it simple:
I use
Play.applicationPath which returns a File
.
Note that there are a few other cool path in the Play class:
- frameworkPath
- javaPath
- templatePath
VirtualFile path = play.vfs.VirtualFile.fromRelativePath("/");
This will give you the path. From the returned object, you can get the File object, get the path as a String using getName()
and do normal file type checks, like exists()
andisDirectory()
etc.
Take a look at the javadoc for more info.
http://www.playframework.org/documentation/api/1.1/play/vfs/VirtualFile.html
You can use also : Play.getFile(".")
this method return a object File
See javadoc : http://www.playframework.org/documentation/api/1.1/play/Play.html#getFile(java.lang.String)
In Play 2.0 (scala) try this:
import play.api.Play.current
val playPath = current.path.getAbsolutePath
In Java Play 2.x project, do this: play.Play.application().getFile(".")
.
精彩评论