M
mt
Hello to all,
I'm creating a web application and I wanto to be able to read/store a
value in a property file. My questions are the following:
1- Is the property file supposed to be in a specific location in the
web application? (i.e. inside the WEB-INF folder) Or it doesn't
matter?
2- Right now the property file is inside a package. I'm able to get
the properties using the code:
//name = package where the property file is located (including the
name of the property file) (i.e. com.___.____.....)
final ResourceBundle rb = ResourceBundle.getBundle(name,
Locale.getDefault(),loader);
result = new Properties();
for (Enumeration keys = rb.getKeys(); keys.hasMoreElements()
{
final String key = (String) keys.nextElement();
final String value = rb.getString(key);
result.put(key, value);
}
I want to be able to store a property during the execution of the
application. The code I'm using is:
//name = package where the property file is located (including the
name of the property file) (i.e. com/.../.../.....)
try{
FileOutputStream outputStream = new FileOutputStream(name);
result.store(outputStream, "----No Comment----");
outputStream.close();
}
But the system is not finding the package that has the property file.
The error I'm getting is:
java.io.FileNotFoundException: com\..\...\...\...\project.properties
(The system cannot find the path specified)
To find out what was happening, inside the "catch" block I created a
new file so I could see where the system was searching for that
package. I'm using Eclipse IDE and the file was created in the
eclipse folder (C:\eclipse\newFile.doc). Is there a way that I can
specify where to look for a file inside a webapplication (I want to
search in the tomcat/webapps/myapp/folder -where the application is
located- instead of the /eclipse folder). Or am I supposed to specify
that in the web.xml? I'm new to this so I highly appreciate any help.
-mt
I'm creating a web application and I wanto to be able to read/store a
value in a property file. My questions are the following:
1- Is the property file supposed to be in a specific location in the
web application? (i.e. inside the WEB-INF folder) Or it doesn't
matter?
2- Right now the property file is inside a package. I'm able to get
the properties using the code:
//name = package where the property file is located (including the
name of the property file) (i.e. com.___.____.....)
final ResourceBundle rb = ResourceBundle.getBundle(name,
Locale.getDefault(),loader);
result = new Properties();
for (Enumeration keys = rb.getKeys(); keys.hasMoreElements()
final String key = (String) keys.nextElement();
final String value = rb.getString(key);
result.put(key, value);
}
I want to be able to store a property during the execution of the
application. The code I'm using is:
//name = package where the property file is located (including the
name of the property file) (i.e. com/.../.../.....)
try{
FileOutputStream outputStream = new FileOutputStream(name);
result.store(outputStream, "----No Comment----");
outputStream.close();
}
But the system is not finding the package that has the property file.
The error I'm getting is:
java.io.FileNotFoundException: com\..\...\...\...\project.properties
(The system cannot find the path specified)
To find out what was happening, inside the "catch" block I created a
new file so I could see where the system was searching for that
package. I'm using Eclipse IDE and the file was created in the
eclipse folder (C:\eclipse\newFile.doc). Is there a way that I can
specify where to look for a file inside a webapplication (I want to
search in the tomcat/webapps/myapp/folder -where the application is
located- instead of the /eclipse folder). Or am I supposed to specify
that in the web.xml? I'm new to this so I highly appreciate any help.
-mt