We all work with files and file paths…I got this recently when I was trying to get the current directory of the user while he is navigating through the application. Issue: At any time, I should get the parent directory of the current user directory and perform the designated actions. Solution: We have system properties which will give us the current user directory… Access the system property using String userDir = System.getProperty(“user.dir”); Now you can user the File Java Class to access the parent directory as String parentDir = new File(userDir).getParent(); For Example: User is in /home/someuser/SeleniumTests/Test1 userDir will have the value /home/someuser/SeleniumTests/Test1 parentDir will have the value /home/someuser/SeleniumTests Hope this helps! Happy Coding!
Being in the industry for almost two decades, one thing that's been constant is change and my curiosity. I In this fast world of IT...being curious, learning and learning by doing is quintessential :) Here is my way of learning and sharing what I learnt!!! Author: Sirisha Reddy G V