I need System.setProperty(String, String)

Hi;

I need to be able to set some system properties (for some unit tests). How do I do this In java it's System.setProperty("key", "value");

thanks - dave


Answer this question

I need System.setProperty(String, String)

  • Mehmet Ozdemir

    To set custom values you will need to use System.setProperties() method
    passing the property table.

    Eg.

      java.util.Properties p = new java.util.Properties();
      p.setProperty("Hello", "Hi");
      System.setProperties(p);
      System.Console.Write(System.getProperty("Hello"));

    Hope this helps.

  • Daison

    Hi David

    Thanks for the feedback. Your request for this JDK 1.2 level method in the future releases has been noted. Like all other requests from our customers about what they would like in our future releases, this request also would go through our planning/investigation process.

    With regards
    Ashwin Raja

  • D-S

    The following may be the right code.

    java.util.Properties p = System.getProperties();
    or
    java.util.Properties p = new java,util.Properties(System.getProperties());

    p.setProperty("Hello", "Hi");
    System.setProperties(p);
    System.Console.Write(System.getProperty("Hello"));


    The latter one has a performance problem when we set many properties.


  • Simba

    be specific please



  • Karthikeyan K

    Hi;

    That's what I am doing. And it's test code so the performance is not critical. But it's a pain to have to do this in 27 places. Please for .net 2.1 add this method as I am sure others will need this too (for common source code).

    thanks - dave

  • Pete Lux

    I have the following in my code:
    System.setProperty("key", "value");

    and the compiler says there is no setProperty(String, String) method.

    thanks - dave

  • I need System.setProperty(String, String)