Java Relative Path Get relativize(String path)

Here you can find the source of relativize(String path)

Description

relativize

License

Open Source License

Declaration

public static String relativize(String path) 

Method Source Code

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

import java.io.*;

import java.util.regex.Pattern;

public class Main {
    public static String relativize(String path) {
        String[] split = path.split(Pattern.quote(File.separator));
        StringBuilder out = new StringBuilder();
        int skip = 0;
        int len = split.length - 1;
        for (int i = len; i >= 0; i--) {
            if (skip > 0)
                skip--;//from  www .  j ava  2  s. co  m
            else {
                String arg = split[i];
                if (arg.equals(".."))
                    skip++;
                else
                    out.insert(0, arg + (i == len ? "" : File.separator));
            }
        }
        return out.toString();
    }
}

Related

  1. relativize(File base, File child)
  2. relativize(File file, File basedir)
  3. relativize(File home, File f)
  4. relativize(File path, File relative)
  5. relativize(final File root, final File target)
  6. relativize(String path)
  7. relativize(String path, String base)
  8. relativizePath(File from, File to)
  9. relativizePath(final File path, final File base)