是否可以访问 Play 之外的文件!应用程序文件夹?
Is it possible to access a file outside a Play! application folder?
我想让两个Play应用程序(部署在同一台服务器上)访问同一个文件夹,但我找不到方法。
是否可以通过文件的绝对路径访问文件,以便我可以将此文件夹放在我的服务器的目录级别并由两个应用程序访问它?
是的,只要对 play app 进程有正确的权限,就可以访问任何文件夹。您可以使用 Java 文件访问文件系统中的任何文件。
Ensure read write permissions accordingly if not Play throws FileNotFoundException
import java.io.File
@Singleton
class ApplicationController @Inject() () extends Controller {
def file = Action {
Ok.sendFile(new File(s"${sys.props("user.home")}/some_file.txt"))
}
}
在上面的示例中,some_file.txt
是通过 http 连接发送的。请注意,如果权限不正确,则会抛出 FileNotFoundException
我想让两个Play应用程序(部署在同一台服务器上)访问同一个文件夹,但我找不到方法。
是否可以通过文件的绝对路径访问文件,以便我可以将此文件夹放在我的服务器的目录级别并由两个应用程序访问它?
是的,只要对 play app 进程有正确的权限,就可以访问任何文件夹。您可以使用 Java 文件访问文件系统中的任何文件。
Ensure read write permissions accordingly if not Play throws FileNotFoundException
import java.io.File
@Singleton
class ApplicationController @Inject() () extends Controller {
def file = Action {
Ok.sendFile(new File(s"${sys.props("user.home")}/some_file.txt"))
}
}
在上面的示例中,some_file.txt
是通过 http 连接发送的。请注意,如果权限不正确,则会抛出 FileNotFoundException