Java Utililty Methods Path Normalize

List of utility methods to do Path Normalize

  1. HOME
  2. Java
  3. P
  4. Path Normalize

Description

The list of methods to do Path Normalize are organized into topic(s).

Method

String normalise(String path)
normalise
return normalise(path, BACK_SLASH_CHAR, SLASH_CHAR);
String normalisePath(final String path)
normalise Path
final char BACK_SLASH = '\\';
final char FORWARD_SLASH = '/';
final String SPACE = " "; 
final String SPACE_ESCAPE = "%20"; 
return path.replace(BACK_SLASH, FORWARD_SLASH).replace(SPACE, SPACE_ESCAPE);
String normalisePath(String path)
Normalises a path by replacing all back slashes with forward slashes.
return path.replace('\\', '/');
String normalisePath(String path)
This normalises a path to ensure it starts with / and does not end with /
if (path != null) {
 path = path.trim();
 if (path.endsWith("/")) {
 path = path.substring(0, path.length() - 1);
 if (!path.isEmpty() && !path.startsWith("/")) {
 path = "/" + path;
 return path;
return "";
String normalize(final boolean absolutize, final String... path)
normalize
if (path == null || path.length < 1) {
 return null;
final StringBuilder sb = new StringBuilder();
int idx = 0;
for (String part : path) {
 if (part.length() < 1 || "/".equals(part)) {
 continue;
...
String normalize(final String path)
Returns normalized path (or simply the path if it is already in normalized form).
if (path == null) {
 return null;
if (path.indexOf('.') == -1 && path.indexOf('/') == -1) {
 return path;
boolean wasNormalized = true;
int numSegments = 0;
...
String normalize(final String path)
normalize
if (path.equals("/")) {
 return "";
final boolean startsWith = path.startsWith("/");
final boolean endsWith = path.endsWith("/");
if (startsWith && endsWith) {
 return path.substring(1, path.length() - 1);
if (startsWith) {
 return path.substring(1);
if (endsWith) {
 return path.substring(0, path.length() - 1);
return path;
String normalize(final String path)
Normalize a path.
String normalized = path;
while (true) {
 int index = normalized.indexOf("//");
 if (index < 0) {
 break;
 normalized = normalized.substring(0, index) + normalized.substring(index + 1);
while (true) {
 int index = normalized.indexOf("/./");
 if (index < 0) {
 break;
 normalized = normalized.substring(0, index) + normalized.substring(index + 2);
while (true) {
 int index = normalized.indexOf("/../");
 if (index < 0) {
 break;
 if (index == 0) {
 return null; 
 int index2 = normalized.lastIndexOf('/', index - 1);
 normalized = normalized.substring(0, index2) + normalized.substring(index + 3);
return normalized;
String normalize(final String pathname)
Normalize.
return pathname.replaceAll("//", "/");
String normalize(String path)
Normalizes the given path (removes superfluous #SEPARATOR separators ).
path = path.replace(SEPARATOR + SEPARATOR, SEPARATOR);
if (path.startsWith(SEPARATOR)) {
 path = path.substring(1);
if (path.endsWith(SEPARATOR)) {
 path = path.substring(0, path.length() - 1);
return path;
...


AltStyle によって変換されたページ (->オリジナル) /