Reading configuration files from the conf directory within a module is a very common occurring in wowza. the following code snippet shows how to read a text file as string from the conf directory. If the file does not exist the code throws an IOException. this example makes use of the environment variable WMSCONFIG_HOME,
/**
* Read a text file as string from the wowza conf directory give the filename
*
* @param filename file name of the file to read
* @return
* @throws IOException
*/
private String readFileFromConfigDirectory(String filename) throws IOException
{
String conf_home = System.getenv("WMSCONFIG_HOME");
File conf_dir = new File(conf_home + File.separator + "conf");
if(conf_dir.exists()) {
// read the file contents here
File file_to_read= new File(conf_dir.getAbsolutePath() + File.separator + filename);
if(file_to_read.exists()) {
String content = new String(Files.readAllBytes(Paths.get(file_to_read.getAbsolutePath())));
return content;
}
else {
throw new IOException("oops! file "+filename+" not found!!");
}
}
else {
throw new IOException("oops! conf directory was not found!!");
}
}