title: How to set environment variable in java
body: <p>I want to set environment variable in JAVA . For this , I have searched a lot in internet and got the following code . </p>
  
  <pre><code>void set_up_environment_var() throws IOException
  {
       ProcessBuilder pb = new ProcessBuilder("CMD.exe", "/C", "SET"); // SET prints out the environment variables  
       pb.redirectErrorStream(true);  
  
       Map&lt;String,String&gt; env = pb.environment();  
  
       String str1 = ";C:\\naved\\bin";
       String path = env.get("Path") ;//+ ";C:\\naved\\bin";  
       System.out.println("ok , I am coming . "+path.toLowerCase().contains(str1.toLowerCase()));
       env.put("Path", path.concat(str1));  
       Process process = pb.start();  
       BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));  
       String line;  
       while ((line = in.readLine()) != null)  
       {  
      //     System.out.println(line);  
       }  
  }
  </code></pre>
  
  <p>But after execution , the envorinment variable is not set in "PATH" varaible . Why ?</p>