Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I add a userprofile variable normally %userprofile%

Tags:

java

I need to add a user profile variable in java, apparently %userprofile% does not work. when I try and enter this into the directory towards the bottom of the code it does not accept it. however I can echo my %userprofil% in command line

userprofile+"\Downloads\file.txt");

like image 367
jerhynsoen Avatar asked Sep 12 '25 12:09

jerhynsoen


1 Answers

String System.getenv(String var)

so

String userprofile = System.getenv("USERPROFILE");

Then manipulate as desired (e.g. append the rest of your path...)

Alternatively, get the whole environment with Map<String,String> System.getenv()

like image 190
John3136 Avatar answered Sep 14 '25 02:09

John3136