Java Path Normalize normalizePath(String _path, boolean _appendFinalSeparator)

Here you can find the source of normalizePath(String _path, boolean _appendFinalSeparator)

Description

Normalize a file system path expression for the current OS.

License

Open Source License

Parameter

Parameter Description
_path path
_appendFinalSeparator controls appendix of separator at the end

Return

normalized path

Declaration

public static String normalizePath(String _path, boolean _appendFinalSeparator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Character that separates components of a file path. This is "/" on UNIX and "\" on Windows. */
    public static final String FILE_SEPARATOR = System.getProperty("file.separator");

    /**/*www.j  a v  a2s . com*/
     * Normalize a file system path expression for the current OS.
     * Replaces path separators by this OS's path separator.
     * Appends a final path separator if parameter is set
     * and if not yet present.
     * @param _path path
     * @param _appendFinalSeparator controls appendix of separator at the end
     * @return normalized path
     */
    public static String normalizePath(String _path, boolean _appendFinalSeparator) {
        if (_path == null) {
            return _path;
        }

        String path = _path.replace("\\", FILE_SEPARATOR).replace("/", FILE_SEPARATOR);
        if (_appendFinalSeparator && !path.endsWith(FILE_SEPARATOR)) {
            path += FILE_SEPARATOR;
        }
        return path;
    }

    /**
     * Normalize a file system path expression for the current OS.
     * Replaces path separators by this OS's path separator.
     * Appends a final path separator unless present.
     * @param _path path
     * @return normalized path
     */
    public static String normalizePath(String _path) {
        return normalizePath(_path, true);
    }
}

Related

  1. normalizePath(final String path)
  2. normalizePath(final String path)
  3. normalizePath(final String path)
  4. normalizePath(final String path)
  5. normalizePath(final String... path)
  6. normalizePath(String absPath)
  7. normalizePath(String filepath)
  8. normalizePath(String fileSystemPath)
  9. normalizePath(String path)