Here you can find the source of getFileRelativeFolders(Path basePath, Path filePath)
public static List<String> getFileRelativeFolders(Path basePath, Path filePath)
//package com.java2s; //License from project: LGPL import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static List<String> getFileRelativeFolders(Path basePath, Path filePath) { List<String> res = new ArrayList<>(); Path relativize = basePath.relativize(filePath).getParent(); if (relativize != null) { Iterator<Path> iterator = relativize.iterator(); while (iterator.hasNext()) { res.add(iterator.next().toString()); }//from w w w . j av a2s. c o m } return res; } }