I need to get relative path from my project to upload photos, however when I run System.getProperty("user.dir"); in my test, it returns /home/user/workspace/Myproject,
but if I run it from my spring controller, it just returns /home/user.
Can anyone provide a insight that probably is happening?
The
user.dirproperty is the current working directory where you are running Java. You’re starting java in/home/user/workspace/Myprojectwhen you run your project but when Spring runs it, it’s not guaranteed to be the same working directory. Are you looking foruser.home(which should always be/home/user) instead?