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

时间:2010-12-28 20:08:50

标签: java red5

我制作了一个应用程序并将其放在webapps中作为新文件夹,比如说appcustom 我想读一些文本文件 我如何通常阅读而不是硬编码路径?

目前我使用的是这样的东西:

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

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

3 个答案:

答案 0 :(得分:2)

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


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));

答案 1 :(得分:0)

Properties props = new Properties();
   // Looks for the file 'database.properties' in {TOMCAT_HOME}\webapps\{RED5_HOME}\WEB-INF\
   FileInputStream in = new FileInputStream(System.getProperty("red5.config_root") + "/database.properties");
   props.load(in);

我发现这种方式非常有助于阅读任何文件。

Here is the link of full example

答案 2 :(得分:0)

相关问题