如何列出Play Framework 2 Scala应用程序中public/images目录中的所有文件? [英] How to list out all the files in the public/images directory in a Play Framework 2 Scala application?

查看:53
本文介绍了如何列出Play Framework 2 Scala应用程序中public/images目录中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想列出我的Scala Play Framework 2应用程序public/images目录中的所有文件名,以便Play应用程序仅将这些文件名列出到HTML页面.该怎么办?

I want to list out all the file names in the public/images directory for my Scala Play Framework 2 application so that the Play Application just lists those file names to the HTML page. How can this be done?

是否存在访问public/images目录以读取文件或列出目录的正确方法?我不想使用绝对目录路径.

Is there a right way to access the public/images directory to read files or list the directory? I don't want to use absolute directory paths.

推荐答案

There is method getFile(relateivePath: String): File on Play object and also in the Application class which returns file relative to application root directory. In your case:

Play.getFile("public/images")

返回 File 对象,代表public/images/目录.您可以调用listlistFiles来获取目录的内容.

return File object, which represent public/images/directory. You can call list or listFiles on it to get contents of the directory.

这篇关于如何列出Play Framework 2 Scala应用程序中public/images目录中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆