Converting a relative path into an absolute path
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) throws Exception {
String separator;
separator = FileSystems.getDefault().getSeparator();
System.out.println("The separator is " + separator);
Path path = Paths.get(new URI("file:///C:/home/docs/users.txt"));
System.out.println("subpath: " + path.subpath(0, 3));
path = Paths.get("/home", "docs", "users.txt");
System.out.println("Absolute path: " + path.toAbsolutePath());
System.out.println("URI: " + path.toUri());
}
}
Related examples in the same category