DotenvBuilder systemProperties method example

In this post under DotEnv, I will show with example the purpose of “systemProperties” method available in DotEnv framework. With the help of this method whatever properties you read from .env file can be added as System properties and accessible using “System.getProperty()” method. Below is the main class showing how to use it Main class…… Continue reading DotenvBuilder systemProperties method example

Retrieve environment values present in file

In previous posts under DotEnv, whenever we called static “load” method on “DotEnv” class it used to load system environment values in addition to environmentvalues present in .env or .env file with custom name. What if we want only the environment values present in the file and not the system environment values. There is way…… Continue reading Retrieve environment values present in file

Accessing an non existing environment key

In this post under DotEnv, I will show with example how to handle retrieving values of environment keys that doesn’t exist. Below is the main class for your reference. Main class 1 package defaultPackage;2 3 import io.github.cdimascio.dotenv.Dotenv;4 5 public class Example6 {6 public static void main(String[] args) {7 Dotenv dotenv = Dotenv.load();8 String value =…… Continue reading Accessing an non existing environment key

Loading environment properties from custom .env file

In all my previous post under DotEnv, I showed how to load environment properties from a file named “.env”. The “.env” file can be present in the project directory or in some other directory. By default, DotEnv is configured to search under project directory. In one of my previous posts, I showed how to change…… Continue reading Loading environment properties from custom .env file

Loading .env file from a specific folder

In previous post under DotEnv, I showed that by default DotEnv checks for “.env” file in the project directory when static “load” method is called. So if your project directory is in “D:\ProgrammingConcepts\JavaSEConcepts\DotEnvConcepts” the “.env” file should be present directly under the “DotEnvConcepts” folder. If present in subfolders under “DotEnvConcepts” it will not load that…… Continue reading Loading .env file from a specific folder

Accessing an environment variable

In this post under DotEnv, I will show with example how to access a particular environment variable. For example I have created “.env” file with below data. Env File MY_ENV_VAR1=some_value1 MY_ENV_VAR2=some_value2 Now to retrieve the value of environment variable “MY_ENV_VAR1” we call the non static “get” method of “DotEnv” class as shown below Main class…… Continue reading Accessing an environment variable

Loading .env files

In this post under DotEnv, I will show with example how to load a .env file. Below is the complete main class Main class 1 package defaultPackage; 2 3 import io.github.cdimascio.dotenv.Dotenv; 4 import io.github.cdimascio.dotenv.DotenvEntry; 5 6 public class Example1 { 7 public static void main(String[] args) { 8 Dotenv dotenv = Dotenv.load(); 9 for(DotenvEntry entry…… Continue reading Loading .env files