java - 如何在Red5中获取应用程序路径(绝对和相对)

标签 java red5

我制作了一个应用程序并将其作为新文件夹放入 webapps 中,例如 appcustom。
我想阅读一些文本文件。
我如何一般地读取而不是硬编码路径?

目前我正在使用这样的东西:

FileReader fr = new FileReader("webapps/appcustom/<<textfilename>>"); // read a file

如何使其通用?因为明天我可能想将应用程序文件夹名称更改为“custApp”或其他名称。

最佳答案

您可以在 Red5 中使用一些系统属性,如果我尝试从通用应用程序类读取资源,我将使用此 block :


FileReader fr = new FileReader(String.format("%s/%s/%s", System.getProperty("red5.webapp.root"), appName, fileName));

需要提供应用程序名称(例如:oflaDemo)和您的文件名。

从 ApplicationAdapter 您可以访问“可用”应用程序名称:


FileReader fr = new FileReader(String.format("%s/%s/%s", System.getProperty("red5.webapp.root"), getScope().getName(), fileName));

从 Servlet,您可以访问完整路径:


FileReader fr = new FileReader(String.format("%s/%s", getServletContext().getRealPath("/"), fileName));

关于java - 如何在Red5中获取应用程序路径(绝对和相对),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4549108/

相关文章:

java - 错误 HTTP : 500 when uploading/sharing file in openmeetings

java - Red5 + Java + Windows 安装 + ant 编译 : it works, 但为什么呢?

Java,java.util.HashMap 无法转换为 org.bson.BSONObject

java - 在SQL中使用一个命令 - 我需要将单词 'Cars' 的所有实例更改为 'Zip-Cars' ,这包括将 'Cars 2' 更改为 'Zip-Cars 2'

java - Red 5 媒体服务器版本 1.0 查找正确的 Java 版本

actionscript-3 - 连接丢失后的 ActionScript NetStream.Publish.BadName 错误

java - 使用Red5需要Java吗

java - 在 Spring 中处理上下文

java - Gson:我们可以在类型适配器中获取序列化的字段名称吗?

java - 我如何检查客户端是否不再通过 Java 中的 TCP 连接?