How to get the real path to the application in the game

as in the servlet:

public void doPost(HttpServletRequest request, HttpServletResponse response)  
  throws ServletException, IOException {  
    String  filePath = config.getServletContext().getRealPath("/");  
}

How to getRealPath in the game?

+3
source share
5 answers

Playing is all about being easy, right? so let it be easier:

I am using    Play.applicationPath , which returns File.

Please note that in the Play class there are some more interesting ways:

  • frameworkPath
  • javaPath
  • templatePath
+5
source
VirtualFile path = play.vfs.VirtualFile.fromRelativePath("/");

This will give you a way. Of the returned object, you can get the File object, as a String to get the path via getName()and perform usual checks the file type, for example exists(), and isDirectory()etc.

Take a look at javadoc for more information.

http://www.playframework.org/documentation/api/1.1/play/vfs/VirtualFile.html

+3

In Play 2.0 (scala), try the following:

import play.api.Play.current
val playPath = current.path.getAbsolutePath
0
source

The project Java Play 2.x, do the following: play.Play.application().getFile(".").

0
source

Source: https://habr.com/ru/post/1786045/


All Articles