0

I set environment variable CONFIG. Is it possible to use it to open file?

String path = "$CONFIG/app/users.json" File file = new File(path); 

PS

I cannot add whole path to file to the property file. It is required to use $CONFIG variable.

2 Answers 2

1

You could use System class's getenv method like:

String path = System.getenv("CONFIG") + "/app/users.json" 

So you could get whatever path you set in CONFIG variable and then you could append further path to it.

Sign up to request clarification or add additional context in comments.

Comments

1

There a built-in method, System.getenv() which returns a Map with all the environment variables, from which you can get the one you need:

Map<String, String> env = System.getenv(); String config = env.get("CONFIG"); //and then String path = config + "/app/users.json"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.