在 Playframework 中获取资源文件作为 InputStream [英] Getting a resource file as an InputStream in Playframework

查看:12
本文介绍了在 Playframework 中获取资源文件作为 InputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Play.classloader.getResourceAsStream(filepath); 

文件路径 - 相对于什么?项目根?游戏框架根?绝对路径?

filepath - relative to what? project root? playframework root? absolute path?

或者 Play.classloader.getResourceAsStream 的用法是错误的?

Or maybe the usage Play.classloader.getResourceAsStream is wrong?

推荐答案

在 Play Framework 中,conf"目录位于类路径中,因此您可以将文件放在那里并使用 getResourceAsStream 打开它.

In the Play Framework the "conf" directory is on the classpath, so you can put your file there and open it with getResourceAsStream.

例如,如果您创建一个文件conf/foo.txt",您可以使用

For example if you create a file "conf/foo.txt" you can open it using

Play.classloader.getResourceAsStream("foo.txt");

这篇关于在 Playframework 中获取资源文件作为 InputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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