Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
firstline1
titleReceiving Arguments and returning Variables
linenumberstrue
package js7;

import java.io.FileWriter;
import java.io.IOException;

public class SetAndGetVariables {

	protected void setVar(String name, String value) throws IOException {
		try {
			String tmpFileName = System.getenv("JS7_RETURN_VALUES");
			FileWriter fw = new FileWriter(tmpFileName, true);             f 
            w.write(name + "=" + value + System.lineSeparator());
            fw.close();
		} catch (IOException ioe) {
			System.err.println("IOException: " + ioe.getMessage());
		}

	}

    protected String getVar(String name){
       return System.getenv(name);
	}

	public static void main(String[] args) throws IOException {

		SetAndGetVariables setAndGetVariables = new SetAndGetVariables();
		System.out.println("var1=" +  setAndGetVariables.getVar("VAR1"));
		setAndGetVariables.setVar("var1", "newValue");
	}

}