Skip to content

Instantly share code, notes, and snippets.

@joakime
Last active August 5, 2020 14:44
Show Gist options
  • Select an option

  • Save joakime/115050ecf66d78560c04fc401e791f94 to your computer and use it in GitHub Desktop.

Select an option

Save joakime/115050ecf66d78560c04fc401e791f94 to your computer and use it in GitHub Desktop.
On Unix / Linux
path [/home/joakim/code/jetty/junk]./is/it/abs=/is/it/abs
path [/home/joakim/code/jetty/junk].\is\it\abs=/home/joakim/code/jetty/junk/\is\it\abs
path [/home/joakim/code/jetty/junk].\\ceres\joakim\abs=/home/joakim/code/jetty/junk/\\ceres\joakim\abs
path [/home/joakim/code/jetty/junk].D:\is\it\abs=/home/joakim/code/jetty/junk/D:\is\it\abs
On Windows
path [C:\Code\Junk]./is/it/abs=C:\is\it\abs
path [C:\Code\Junk].\is\it\abs=C:\is\it\abs
path [C:\Code\Junk].\\ceres\joakim\abs=\\ceres\joakim\abs
path [C:\Code\Junk].D:\is\it\abs=D:\is\it\abs
package fs;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ServletApiExample
{
public static void main(String[] args)
{
Path multipartLocation = Paths.get(System.getProperty("user.dir"));
getPart(multipartLocation, "/is/it/abs");
getPart(multipartLocation, "\\is\\it\\abs");
getPart(multipartLocation, "\\\\ceres\\joakim\\abs");
getPart(multipartLocation, "D:\\is\\it\\abs");
}
private static void getPart(Path multipartLocation, String partLocation)
{
Path path = multipartLocation.resolve(partLocation);
System.out.printf("path [%s].%s=%s%n", multipartLocation, partLocation, path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment