Create a path relative to root, C:/, D:/ etc - Java File Path IO

Java examples for File Path IO:Path

Description

Create a path relative to root, C:/, D:/ etc

Demo Code

import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) {
        /*from w  ww  .j  a v a2  s .  c  o  m*/
        Path path01 = Paths.get("folder1/folder2/folder3/test.txt");        
        Path path02 = Paths.get("/folder1", "folder2/folder3/test.txt");        
        Path path03 = FileSystems.getDefault().getPath("/folder1/folder2/folder4", "test.txt");
        Path path04 = FileSystems.getDefault().getPath("/folder1/folder2/folder3/test.txt");
        Path path05 = Paths.get(URI.create("file:///folder1/folder2/folder3/test.txt"));
    }
}

Related Tutorials