Ask coding questions

← Back to all posts
How do i read .env files java
jack1ehanna (0)

I am trying to make a discord bot in repl-it and i want to make the token secret by putting it in an env files, Now the problem is i don't know how to use an env files inside of java code and open it

Comments
hotnewtop
Coder100 (19277)

Slight corrections, you can actually set environment variables with the new environment variables:

And to read keys, use System.getenv()

Note: This will NOT work with users that don't have access to your repl! Your secrets are safe!

VulcanWM (3097)

So click on the padlock icon of the left hand side of the page (the navigation bar)
Then enter the key and value of the variable you want to put in the .env file
Then do the code: System.getenv(“key”) to get the variable from the .env file