/** * Gets the absolute path to the given file, with the directory separator * standardized to forward slash, like most platforms use. * * @param file The file whose path will be obtained and standardized. * @return The file's standardized absolute path. */ public static String getPath(final File file) { final String path = file.getAbsolutePath(); final String slash = System.getProperty("file.separator"); return getPath(path, slash); }
/** * Gets the absolute path to the given file, with the directory separator * standardized to forward slash, like most platforms use. * * @param file The file whose path will be obtained and standardized. * @return The file's standardized absolute path. */ public static String getPath(final File file) { final String path = file.getAbsolutePath(); final String slash = System.getProperty("file.separator"); return getPath(path, slash); }
String path = FileUtils.getPath(classLocation).replace('\\', '/');
String path = FileUtils.getPath(classLocation).replace('\\', '/');
@Test public void testGetPath() { // test that Windows-style paths get standardized assertEquals("C:/path/to/my-windows-file", FileUtils.getPath( "C:\\path\\to\\my-windows-file", "\\")); // test that there are no changes to *nix-style paths assertEquals("/path/to/my-nix-file", FileUtils.getPath( "/path/to/my-nix-file", "/")); // test that an already-standardized path stays good on Windows assertEquals("/path/to/my-nix-file", FileUtils.getPath( "/path/to/my-nix-file", "\\")); }