Set environment variable from java

Posted on 2009-02-19
Last Modified: 2012-05-06

I need to set system environment variable from java to work cross platform.
just like set in dos, export linux
Any ideas?
Question by:d2marcelo
    LVL 92

    Expert Comment

    you can't set environment variables using java

    Author Comment

    I have a class that will read some paths from a property file and the path has the environment variable on it. How can I make sure java knows what it is.
    I try running batch file to set those up before run java but it doesn't work.
    LVL 92

    Expert Comment

    you can pass properties on the command line
    or you can load the properties file from your application


    Author Comment

    can you show me how to load the property from the app.  like  path=value
    LVL 92

    Accepted Solution

    Properties props = new Properties();
    InputStream in = new FileInputStream(new File(pathToProperties));

    String value = props.getProperty(path);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now