FileUtil { public static String joinPath(String... elements) { return joinPath(File.separatorChar, elements); } private  FileUtil(); static String joinPath(String... elements); static void forceMkdirs(File dir); static void safeCopyFile(File child, File destChild); static void writeAndForce(Path path, byte[] data); static String canonicalize(CharSequence path); static File canonicalize(File file);  }
@Test public void testUnixPaths() { Assert.assertEquals("/tmp/far/baz/lala", joinPath('/', "/tmp/", "/", "far", "baz/", " Assert.assertEquals("tmp/far/bar", joinPath('/', "tmp Assert.assertEquals("/tmp/far/bar", joinPath('/', "/tmp/", "far", "bar/")); Assert.assertEquals("/tmp/far/bar", joinPath('/', "/" + "/tmp/", "far", "bar/")); }
@Test public void testWindozePaths() { Assert.assertEquals("C:\\temp\\far\\baz\\lala", joinPath('\\', "C:\\", "temp\\", "\\far", "\\baz\\", "\\", "\\", "\\lala")); Assert.assertEquals("\\\\myserver\\tmp\\far\\baz\\lala", joinPath('\\', "\\\\myserver\\tmp\\\\far\\baz\\\\\\\\lala")); Assert.assertEquals("C:\\temp\\far\\baz\\lala", joinPath('\\', "C:\\temp\\\\far\\baz\\\\\\\\lala\\")); }