Here you can find the source of getRelativePath(String fullPath, String homeFolderPath)
Parameter | Description |
---|---|
fullPath | a parameter |
homeFolderPath | a parameter |
public static String getRelativePath(String fullPath, String homeFolderPath)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.nio.file.Paths; public class Main { /**/*from w ww . java 2s . c o m*/ * Return the path of the folder as in the database entry of the file * * @param fullPath * @param homeFolderPath * @return */ public static String getRelativePath(String fullPath, String homeFolderPath) { String parentPath = ""; try { URL parentURL = Paths.get(fullPath).toUri().toURL(); URL homeFolderURL = Paths.get(homeFolderPath).toUri().toURL(); parentPath = parentURL.getPath().replace(homeFolderURL.getPath(), ""); // Decode the URL parentPath = URLDecoder.decode(parentPath, "UTF-8"); // Remove last slash of the string if (parentPath.length() > 0 && parentPath.charAt(parentPath.length() - 1) == '/') { parentPath = parentPath.substring(0, parentPath.length() - 1); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return parentPath; } }