I am wondering how to get the relative path name? Any existing library can help this?
c:\123 c:\123\1234\zaq\erf
I would like to get something like 123/1234/zaq/erf
I am wondering how to get the relative path name? Any existing library can help this?
c:\123 c:\123\1234\zaq\erf
I would like to get something like 123/1234/zaq/erf
Use the relativize()
method in the URI
class. Construct a URI from the base file path and then relativize your absolute file path.
String s = new File("c:\\123").toURI().relativize(new File("c:\\123\\1234\\zaq\\erf").toURI()).getPath();
If you are using Java 7, there is the relativize method of the Path class that does what you need.