Changing values in a properties file

Hi,
I'm working in a Struts environment and I am trying to open a .properties file in my WEB-INF/classes/ (*.properties) directory and allow the user to change those values and write them back.
I access the properties by pulling them out in a Map:
Locale locale = LocaleContextHolder.getLocale();
         ResourceBundle resBundle = ResourceBundle.getBundle(SP_PROPERTIES_FILE,locale);
         Enumeration propertyKeys = resBundle.getKeys();
          Map spProperties = new HashMap();
         while (propertyKeys.hasMoreElements()) {
             String key = (String) propertyKeys.nextElement();
             if(key != null){
                  key = key.trim();
             String value = resBundle.getString(key);
             if(value != null ){
                  value = value.trim();
             spProperties.put(key, value);
         I then change the values depending on their keys, but it is after this step I am unsure how perform the write back.
Thanks,

A ResourceBundle is a read-only object. It doesn't provide any methods for updating. If you want to allow your users to update the data, the code will have to update the underlying properties file. This also is impossible if your application server doesn't expand the application but runs it from a WAR or EAR archive.
[Edit] And even at that, allowing users to update properties files in a multi-user environment is risky -- if two users update the file at the same time, it's easy to lose one of the updates.

Similar Messages

  • Can a Deployment Plan Modify Values in a .properties file?

    I'm using JDeveloper 11.1.1.6.0 and Weblogic 10.3
    I am currently in the process of creating a plan.xml file for our application, but we have a few properties files that contain configuration information. This information needs to change depending on the environment that we are deploying to. Is it possible to do this through a plan.xml or would we have to use some other method?
    Example:
    File: conf.properties
    ------start file-----
    A=1
    B=2
    C=3
    -----end file-----
    We would need to be able to change the value of B to be 5 instead of 2 if we are deploying to our test environment.

    As far as I can tell, what you linked is just using the deployment plan's XPath to update a value in the web.xml which is standard procedure. However, I am curious of being able to update values in a .properties file which is not an XML file, and thus can't be read by XPath. Is this possible or can the deployment plans only modify XML documents?
    [EDIT] From what I've been finding it seems I've confirmed that it can only override XML files, or atleast I've found no indications that it can do anything other than XML files. Though now I'm having issues of it overriding custom XML files. EG: I have a wf_client_config.xml file in the WAR's class path that I need to update depending on the environment, but have not been able to have the deployments recognize the override that I have listed in the plan.xml.
    So I guess now my question is, do I ened to do anything special to get it to recognize an XML file on the class path vs a standard xml file such as web.xml? Or should I make this a new topic?
    Edited by: mBaldwin on Jan 8, 2013 11:45 AM
    [EDIT 2] Marking this as resolved, it appears as though the plan.xml will only modify settings that could be modified by Weblogic naturally and it is not able to modify items that are on the classpath of the application.
    Edited by: mBaldwin on Feb 26, 2013 12:08 PM

  • Changing value when reading from file

    When I am reading from a text tab-delimited file labview is returning a changed value. For example, the value should be 337478.47 but labview is returning 336727. I have tried changing the array to EXT, it is currently DBL, and that didnt seem to change anything.
    I am using LabView 8.
    Attachments:
    read_from_file2.vi ‏25 KB
    test data.txt ‏5 KB

    Your numbers are fine. Just right-click on your indicators and select the desired format and precision. (By default, it only shows 6 significant digits).
    See if this works.
    LabVIEW Champion . Do more with less code and in less time .

  • Best approach to change values in .properties file dynamically

    Hi ,
    I am using Jdev 11.1.1.5 . I wanted to change the values used in .properties file (like say a fe email addresses which happen to be different for Test/Prod/Dev instances) dynamically using something like a deployment plan.
    One way to do the same is to include it in a shared libary and do a one -time deployment to the server.
    Are there any better ways like a deployment plan , which unfortunately I think can change values dynamically on for web.xml , weblogic.xml type of files.

    I am using a shared library which takes care of the cases mentioned above.

  • Changing values in property file inside a jar in an ear

    Hi,
    I have an application that contains EJB. The environment values needed for initial context of the ejb is kept in a .properties file. I have created an ear of the application. Inside the ear there is a jar which contains the .properties file. I need to deploy the ear to different environments. However before deploying I need some kind of script to change the values in the .properties file inside the jar in the ear.
    Can anyone provide some help/pointers about how can I achieve it (Using ANT/WLST)

    WLST does not have any capability to update a JAR.
    WLS 10.3 (still in tech preview) has the ability to override properties
    files inside the jar with an external properties file. This would allow you
    to deploy the same ear to different environments, and then only deploy a
    different properties file in the plan directory.
    <Rishi Shah> wrote in message news:[email protected]..
    Hi,
    I have an application that contains EJB. The environment values needed for
    initial context of the ejb is kept in a .properties file. I have created an
    ear of the application. Inside the ear there is a jar which contains the
    .properties file. I need to deploy the ear to different environments.
    However before deploying I need some kind of script to change the values in
    the .properties file inside the jar in the ear.
    Can anyone provide some help/pointers about how can I achieve it (Using
    ANT/WLST)

  • Changing a .properties file from within a programme

    Hi, I was just wondering is there anyway that i can change a .properties file from within a programme?
    I have certain values in the .properties file and I want to add a username and password to the file once it has been entered in a login part of the programme.
    I have had a look at the docs and can not seem to find any suitable methods.
    Cheers Gareth.

    store is a good method.
    In practical use, sometimes you have a .properties file full of comments (properties files are to be modified by humans, and humans need comments), but they are not retrieved by "load" so they will not be stored back by "store". It's a pity that it happens (the equivalent Windows API, WritePrivateProfileString, has a better behaviour).
    Maybe someone has written a method that can modify a properties file, without changing the order of the pairs name=value and without throwing out comments.

  • Reading values from properties file

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

  • How can i remove a key and its value from properties file

    hi all,
    i want remove a particular key and associated value from the
    properties file. is their any standard way of doing?
    thanks inadvance
    daya

    hi,
    thanks
    i am able to remove the key,
    one more question how can avoid storing date and time
    in properties file.
    thanks
    daya

  • Loading values into drop down through properties file.

    Hi all,
    Can any one please let me know how to read a drop down through properties file I have two drop downs. I need to read the drop down values through the properties file .
    I would appreciate if you can provide me with the sample code to do this(i mean similar kind of operation)
    Say for example
    if i have in the properties file
    months.properties
    Month = "january,february,march.....december"
    january = "monday,tuesday, wednesday"
    for the first drop down i need to load the months i.e., january, february, march etc.
    After selecting the first drop down say january, then it should show me monday,tuesday and wednesday in the second drop down.
    I know it's a begineers question. any help would be appreciated.
    Thanks in advance for your help
    regards,
    sam

    Actually i want to use Jstl tag for this
    <select name="secQst1">
    <c:forEach var="flaglistdetail" items="${flaglist}">
    <option value="<c:out value="${flaglistdetail.seqId}"/>"><c:out value="${flaglistdetail.seqDesc}"/></option>
    </c:forEach>
    </select>
    The above operation is for getting the drop down values for the database. I want to hard code the values in the properties file and read it in the action and want to get it through the select tag.
    private Properties _appConfig;
         private static final String APP_CONFIG_NAME = "AppConfigProperties.properties";
    if (_appConfig == null) {
    _appConfig = new Properties();
    try {
    appConfig.load(FileUtil.getFileAsStream(APPCONFIG_NAME));
    } catch (Exception e) {
    throw new RuntimeException("can not find "
    + APP_CONFIG_NAME, e);
    I was trying to do the above thing. but for some reason i couldn't get it.
    if you have any sample code which does the same thing like this would be helpful

  • Default properties file

    Hi,
    My scenario is, I have 2 or more language properties files for different langauges. My problem is, if the specified key element is not there in the corresponding properties file, it has to take the corresponding key value from English properties file. Is there any way to do so?
    Thanks in advance,
    Prasad.

    Hi,
    If you want to modify default values for the whole CloverETL engine, you can modify defaultProperties file directly. The whole path of this file is mentioned in our documentation.
    But if you want to change some default values just for the current graph, you can create a new file with only those properties you need to override. Then name this file e.g. as modifiedProperties (without any suffix) and place it into project directory (i.e. right next to .project, .claspath and workspace.prm files of desired project). Open Run configuration of the graph, and fill -config modifiedProperties into Program Arguments text area.
    That is all. If you did it correctly, this line should be visible in graph run log:
    INFO  [main] - Loading Clover properties from file:modifiedProperties
    If this does not help you, please post also version of your software and version of CloverETL.
    Please, do not hesitate to ask if something was unclear.
    Best regards,
    Lubos Imriska
    CloverCARE Support
    Javlin a.s.

  • Accessing other DC properties file

    Hi All,
    I am able to access the properties file within same DC. Now I am trying to access the properties file from other DC but no luck.
    Accessing Local file : ResourceBundle rb = ResourceBundle.getBundle(firstFile);
    kindly help me out in this.
    regards,
    Suresh

    Hi Runak,
    Thanks for the link.
    Can i change the properties file out of the project, what i mean is every time I add/delete a key-value pair in properties file do i have to compile and deploy the whole project again???
    Is there any way I can change the proerties file without having to compile and deploy the project every time properties file is modified??
    Cheers
    kush

  • Need example of properties file use

    I'm writing a text based adventure game to get some practice with the Java language. The only thing that's proving to be difficult is saving the game. I need an example of a class for basic properties operations. I've found various tutorials that all have some helpful information, but putting it all together isn't working for me. Here is what I have.
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    public class SaveGame{
    public static void CreateSave(String name){//create the save file
        try{
            FileWriter fstream = new FileWriter(name+".properties");
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("*-=Character Information=-*");
            out.write("name= \ngender= \n");
            out.write("*-=Basic Stats=-*");
            out.write("str= \nagl= \nend= \nchr= \nitl= \nlck= \n");
            out.close();
            }catch(Exception e){System.err.println("Error: " + e.getMessage());}
    }//CreateSave
    public static void SaveStatus/*save all variables to the file*/
    (double str, double agl, double end, double chr, double itl,
      double lck, String name, char gender){
    // I don't know how to edit values
    }//SaveStatus
    public static void ReadSave(){//reads the file and sends the variable back to main class
    }//ReadSave
    }//class The big thing is, I don't know how to edit the values in the properties file. I can handle reading them but i don't know how to convert the string values to int, double, etc. Thanks in advance.

    Dillon_91 wrote:
    Thanks for those.
    Can you link to a decent tutorial on the properties class? Most of what I've found is a little more technical than I'm ready for, and they don't have examples.Suns own Java tutorial has some code snippets, that should get you going - [Properties tutorial|http://java.sun.com/docs/books/tutorial/essential/environment/properties.html]

  • UNable to locate Properties files from Servlets

    I have a Web App deployed in the default domain (domain1)that contains a servlet which needs to read in values from a .properties file from the filesystem. However, whenever I try to use it, I always end up with a FileNotFoundException.
    I tried keeping the properties file in the d:\Sun\AppServer7\bin as well as d:\Sun\AppServer7\domains\Domain1\server1\bin and still get the same exception.
    Can anyone tell me where I need to keep the .properties file? FYI, I have deployed the same on Tomcat 4.x and the same app worked perfectly (with the prop file in d:\tomcat4\bin directory).
    Thanks,
    Chetan

    Try the instance config directory. In your case, this is probably D:\Sun\AppServer7\domains\domain1\server1\config.

  • Incorrect save propertie file

    Hi!
    I have the next propertie file Settings in folder Config:
    [LOCALE]
    Language=en
    Country=US
    I my code I have:
    private static Properties properties;
    private static final String FILE_NAME = "config" + File.separator + "Settings";
         private void initialization() {
              FileReader fileReader;
              try {
                   properties = new Properties();
                   fileReader = new FileReader(FILE_NAME);
                   properties.load(fileReader);
                   Locale.setDefault(new Locale(properties.getProperty("Language"), properties.getProperty("Country")));
                   fileReader.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void setLocale(Locale locale) {
              FileWriter fileWriter;
              try {
                   properties.setProperty("Language", locale.getLanguage());
                   properties.setProperty("Country", locale.getCountry());
                   fileWriter = new FileWriter(FILE_NAME);
                   properties.store(fileWriter, "");
                   fileWriter.close();
                   Locale.setDefault(locale);
              } catch (IOException e) {
                   e.printStackTrace();
    When I change language I call method setLocale and the result is that in my propertie file I have:
    #Wed Apr 09 19:18:22 EEST 2008
    Language=ru
    [LOCALE]=
    Country=RU
    Why?
    I need the next content in file:
    [LOCALE]
    Language=ru
    Country=RU

    change location in my applicaton
    e.g user work with English version and when want to chagne language to russian , in my application I change location (save in propertie file)
    Internationalization.setLocale(new Locale("ru", "RU"));
    public static void setLocale(Locale locale) {
              FileWriter fileWriter;
              try {
                   properties.setProperty("Language", locale.getLanguage());
                   properties.setProperty("Country", locale.getCountry());
                   fileWriter = new FileWriter(FILE_NAME);
                   properties.store(fileWriter, null);
                   fileWriter.close();
                   Locale.setDefault(locale);
              } catch (IOException e) {
                   e.printStackTrace();
         }

  • Changing properties file value without redploying code

    Hi,
    If I use properties file colors.properties in my web dynpro application for storing key-value pairs as
    color1=RED
    color2=BLUE
    color3=GREEN
    is it possible to change colors.properties  in future to show new colors
    color1=ORANGE
    color2=YELLOW
    color3=PURPLE
    without redeploying code ? through Visual Admin / Config tool  ?
    If not, what is the other way to avoid hard coded values in Web Dynpro Java ?
    Thanks !!

    Hi,
    Its can be achieved using the WDConfiguration API of Java Webdynpro.
    The details are given in the blog below;
    /people/daniel.wirbser/blog/2005/09/28/properties-files-in-web-dynpro-applications-how-to-use-the-wdconfiguration-api
    Also for changing this properties all we need to do is from Visual Administrator/Config tool(changing from config tool will need a re-start)
    Proceed as follows to start the Visual Administrator:
           1.      Start the Visual Administrator by double-clicking on file go.bat in the file directory C:\usr\sap\<System ID>\<System Number>\j2ee\admin, in which the J2EE Engine is installed. For example, the background file can be stored in directory C:\usr\sap\J2E\JC00\j2ee\admin.
    You can find a description of the Visual Administrator in the SAP Library under SAP NetWeaver u00AE Application Platform (SAP Web Application Server) u00AE J2EE Technology in the SAPWeb Application Server u00AE Administration Guide u00AE Server Administration u00AE SAP J2EE Engine Administration Tools u00AE Visual Administrator.
           2.      Navigate to directory Server 0/Services/ Configuration Adapter / webdynpro/ <sap.com/Your namespace>/ <Your Web dynpro application>
           3.      Select the property file
           4.      The Visual Administrator opens so that you can edit the values. You can change or redefine the parameters and check the option "Use Custom " to take the new value.
    Thats all.
    One more URL is
    http://help.sap.com/saphelp_nw04/helpdata/en/09/a4d6a674bc1d4a9e74abf81bed3ef6/frameset.htm
    Regards
    Priya

Maybe you are looking for

  • Sale Order & Production Order

    Hi! Friends is there any table that links Sale Order and Production Order.  In a report i need to display the Production order based on the sale order . as there is no key field for the table MSEG im not able to use it. i have tried using the table A

  • Complex headache in the PO history. Wrong postings in MIGO,MIRO

    Much appreciate if anyone could help on this issue. What we have done: we have a Purchase Order of 3 line items with the quantity in 300,200,100, respectively. the net price for each unit is $1. In MIGO: 1. we posted MIGO with wrong quantity and wron

  • Auto-filter in PDF-file?

    In my PDF file, I have tables with data. Is there an auto-filter function to use so that you can select data?

  • How can i unlock my iphone if i forgot my password?

    how can i unlock my iphone if i forgot my password?

  • What accounts for *intermittent* Error -8 failures?

    I've been following this group carefully, and configured my router and MacBookPro so that video iChat works successfully on my home wireless network. SOMETIMES. This is too weird, and I'm on the verge of giving up. First, I get it working fine. Then