Paving my own Path..

In other words: Path related examples..

Normalizing a Path

import java.nio.file.Paths;
import java.nio.file.Path;
 
public class App {
    public static void main(String[] args) {
        final Path normalizeMe = Paths.get("./foo/bar/.././.");
        final Path normalized = normalizeMe.normalize();
        System.out.println(normalized);
    }
}

The output will be..

Resolving a Path

Give me the path to the target including the directory it resides in!
import java.nio.file.Paths;
import java.nio.file.Path;
 
public class App {
    public static void main(String[] args) {
        final Path directoryPath = Paths.get("C:", "Users", "Koray Tugay");
        final Path targetPath = Paths.get("foo", "bar", "mymp3.mp3");
        System.out.println(directoryPath.resolve(targetPath));
    }
}

The output will be..

Relativizing a Path

Give me the Path that shows how to get from directory to target.
import java.nio.file.Paths;
import java.nio.file.Path;
 
public class App {
    public static void main(String[] args) {
        final Path directoryPath = Paths.get("C:", "Users", "Koray Tugay");
        final Path targetPath = Paths.get("C:", "Users", "Koray Tugay", "foo", "bar", "mymp3.mp3");
        System.out.println(directoryPath.relativize(targetPath));
    }
}

and the output will be..