Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Red5中获取应用程序路径(绝对和相对)_Java_Red5 - Fatal编程技术网

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

Java 如何在Red5中获取应用程序路径(绝对和相对),java,red5,Java,Red5,我制作了一个应用程序,并将其作为新文件夹(比如appcustom)放在webapps中。 我想读一些文本文件。 我如何一般地阅读而不是硬编码路径 目前,我正在使用类似以下内容: FileReader fr = new FileReader("webapps/appcustom/<<textfilename>>"); // read a file FileReader fr=newfilereader(“webapps/appcustom/”);//读文件 如何使其通用

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

目前,我正在使用类似以下内容:

FileReader fr = new FileReader("webapps/appcustom/<<textfilename>>"); // read a file
FileReader fr=newfilereader(“webapps/appcustom/”);//读文件
如何使其通用?因为明天我可能想将应用程序文件夹名称更改为“custApp”或其他名称

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);
我发现这种方法在阅读任何文件时都非常有用


您可能需要检查此项

您可以在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));