Created
September 17, 2018 02:11
-
-
Save MrMe42/5d6a84813023baea6e38c048e682174c to your computer and use it in GitHub Desktop.
Go back n directories JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void downDir(int levels) { | |
String oldPath = System.getProperty("user.dir"); | |
String[] splitedPathArray = oldPath.split("/"); | |
levels = splitedPathArray.length - levels; | |
List<String> splitedPathList = Arrays.asList(splitedPathArray); | |
splitedPathList = splitedPathList.subList(0, levels); | |
String newPath = String.join("/", splitedPathList); | |
System.setProperty("user.dir", newPath); | |
} | |
/* | |
you can call this method and specify number of levels down you want to go in file sys. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment