Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("users.txt");

    if (path.toFile().exists()) {
        System.out.println("Real path: " + path.toRealPath(LinkOption.NOFOLLOW_LINKS));
    } else {//from w w  w  .  j a  v a 2s .  co m
        System.out.println("The file does not exist");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Path p2 = Paths.get("test2.txt");
    // Follow link for p2, if it is a symbolic link
    Path p2RealPath = p2.toRealPath();
    System.out.println("p2RealPath:" + p2RealPath);
    Path p3 = Paths.get("test3.txt");
    // Do not follow link for p3, if it is a symbolic link
    Path p3RealPath = p3.toRealPath(LinkOption.NOFOLLOW_LINKS);
    System.out.println("p3RealPath:" + p3RealPath);

}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get(new URI("file:///C:/home/docs/users.txt"));
    File file = new File("C:\\home\\docs\\users.txt");
    Path toPath = file.toPath();/*from   w w  w  . java2  s  . c o m*/
    System.out.println(toPath.equals(path));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path p = Paths.get(new URI("file:///tmp.txt"));
    System.out.println(p);//w  ww. j a  v a  2 s . c  om
    Files.delete(p);
}

From source file:Main.java

public static void main(String[] args) {
    Path path = Paths.get("C:/home/docs/users.txt");
    FileSystem fileSystem = path.getFileSystem();
    Set<String> supportedViews = fileSystem.supportedFileAttributeViews();

    for (String view : supportedViews) {
        System.out.println(view);
    }//w  ww .j  a  v  a2s.c  o m
}

From source file:Main.java

public static void main(String[] args) {

    Path path01 = Paths.get("/tutorial/Java/JavaFX/Topic.txt");
    Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt");

    //compare using Path.compareTo
    int compare = path01.compareTo(path02);
    System.out.println(compare);/*from w ww  .j a  va  2s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {

    Path path01 = Paths.get("/tutorial/Java/JavaFX/Topic.txt");
    Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt");

    boolean sw = path01.startsWith("/tutorial/Java");
    System.out.println(sw);/*w  w w .j  a v  a 2 s  .com*/

}

From source file:Main.java

public static void main(String[] args) {

    Path path01 = Paths.get("/tutorial/Java/JavaFX/Topic.txt");
    Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt");

    boolean ew = path01.endsWith("Topic.txt");

    System.out.println(ew);//from   ww  w.  j  ava2  s . c o  m

}

From source file:Main.java

public static void main(String[] args) {
    Path path1 = Paths.get("/home/docs/users.txt");
    Path path2 = Paths.get("/home/docs/users.txt");
    Path path3 = Paths.get("/home/music/A.mp3");

    testCompareTo(path1, path2);//from  www.  ja  v a2 s  .  c  o  m
    testCompareTo(path1, path3);

}

From source file:Main.java

public static void main(String[] args) {
    Path path1 = Paths.get("/home/docs/users.txt");
    Path path2 = Paths.get("/home/docs/users.txt");
    Path path3 = Paths.get("/home/music/A.mp3");

    testSameFile(path1, path2);//from  w w  w.ja va 2 s.co m
    testSameFile(path1, path3);
}