Windows environment variables


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Windows environment variables

  1. #1
    Shawn Guest

    Windows environment variables


    How do I get and set Windows environment variables from within a Java app.?
    For example, if I set "TEMP=C:\TEMP" in the system properties, how do I
    retrieve "C:\TEMP"?

  2. #2
    Paul Clapham Guest

    Re: Windows environment variables

    First of all, don't use environment variables to pass information to Java
    programs. The Java way to pass small amounts of constant information into a
    program is to use a properties file; see the class java.util.Properties.
    However, if you need to pass an existing environment variable, you use
    the -D parameter on the "java" command, like this in Windows:

    java -DTEMP=%TEMP% yourClass

    and then in the Java program you get the TEMP system property, like this:

    String temp = System.getProperty("TEMP");

    PC2

    "Shawn" <shawnh@delphiresearch.com> wrote in message
    news:3b55f11e$1@news.devx.com...
    >
    > How do I get and set Windows environment variables from within a Java

    app.?
    > For example, if I set "TEMP=C:\TEMP" in the system properties, how do I
    > retrieve "C:\TEMP"?




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center