DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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"?




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links