Skip to content

Instantly share code, notes, and snippets.

@MrMe42
Created September 17, 2018 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrMe42/5d6a84813023baea6e38c048e682174c to your computer and use it in GitHub Desktop.
Save MrMe42/5d6a84813023baea6e38c048e682174c to your computer and use it in GitHub Desktop.
Go back n directories JAVA
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