IoUtils { public static Path addExtension(Path srcPath, String newExt) { Preconditions.checkArgument(newExt != null, "extension is null"); if (srcPath.getNameCount() == 0) { return srcPath; } String filename = srcPath.getFileName().toString(); return srcPath.resolveSibling(filename + "." + newExt); } private  IoUtils(); static PrintWriter openPrintWriter(File file); static PrintWriter openPrintWriter(File file, boolean append); static PrintWriter openPrintWriter(File file, String encoding, boolean append); static BufferedWriter openBufferedWriter(File file); static BufferedWriter openBufferedWriter(File file, String encoding, boolean append); static BufferedReader openReader(File file); static BufferedReader openReader(File file, String encoding); static void write(Properties props, File outFile); static Properties readProperties(File inFile); static Properties readProperties(File inFile, String encoding); static void writeProperties(Properties props, File outFile); static Path addExtension(Path srcPath, String newExt); static Path extractPathFromURI(String uriStr); static Path extractPath(URI uri);  }
@Test public void testAddExtension() { assertEquals(Paths.get("/home/user.ext"), IoUtils.addExtension(Paths.get("/home/user"), "ext")); assertEquals(Paths.get("home/user.ext"), IoUtils.addExtension(Paths.get("home/user"), "ext")); assertEquals(Paths.get("home/user.ext"), IoUtils.addExtension(Paths.get("home/user/"), "ext")); assertEquals(Paths.get("user.ext"), IoUtils.addExtension(Paths.get("user"), "ext")); assertEquals(Paths.get("user.ext"), IoUtils.addExtension(Paths.get("user/"), "ext")); }