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: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.equals
    if (path01.equals(path02)) {
        System.out.println("The paths are equal!");
    } else {/*from   ww w .j  ava  2  s.  co  m*/
        System.out.println("The paths are not equal!");
    }
}

From source file:Test.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);/*from ww w . j  a v  a 2 s .  c  o m*/
  }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path firstPath = Paths.get("/home/music/users.txt");
    Path secondPath = Paths.get("/docs/status.txt");
    System.out.println("exists (Do not follow links): " + Files.exists(firstPath, LinkOption.NOFOLLOW_LINKS));

}

From source file:Test.java

public static void main(String[] args) throws IOException {
    Path path = Paths.get("/users.txt");
    byte[] contents = Files.readAllBytes(path);

    for (byte b : contents) {
        System.out.print((char) b);
    }//from   w w  w  .j  av a  2 s  .  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 Files.isSameFile
    try {//from   w  ww . j  av a2s  .  c  o  m
        boolean check = Files.isSameFile(path01, path02);
        if (check) {
            System.out.println("The paths locate the same file!");
        } else {
            System.out.println("The paths does not locate the same file!");
        }
    } catch (IOException e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path firstPath = Paths.get("/home/music/users.txt");
    Path secondPath = Paths.get("/docs/status.txt");

    System.out.println("exists: " + Files.exists(firstPath));
    System.out.println("notExists: " + Files.notExists(firstPath));

}

From source file:Main.java

public static void main(String[] args) {
    Path path = Paths.get("./Main.java");
    try (Stream<String> lines = Files.lines(path)) {
        lines.forEach(System.out::println);
    } catch (IOException e) {
        e.printStackTrace();//from w  ww  .ja v  a2s .  c o  m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path sourceFile = Paths.get("C:/home/docs/users.txt");
    Path destinationFile = Paths.get("C:/home/music/users.txt");
    Files.move(sourceFile, destinationFile, StandardCopyOption.ATOMIC_MOVE);

}

From source file:Main.java

public static void main(String[] args) {
    Path dir = Paths.get(".");
    System.out.printf("%nThe file tree for %s%n", dir.toAbsolutePath());
    try (Stream<Path> fileTree = Files.walk(dir)) {
        fileTree.forEach(System.out::println);
    } catch (IOException e) {
        e.printStackTrace();/*from w w  w  .  j a  v  a2s.  c om*/
    }
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path firstPath = Paths.get("/home/music/users.txt");
    Path secondPath = Paths.get("/docs/status.txt");
    System.out.println("From firstPath to secondPath: " + firstPath.relativize(secondPath));
    System.out.println("From secondPath to firstPath: " + secondPath.relativize(firstPath));
    System.out.println("exists (Do not follow links): " + Files.exists(firstPath, LinkOption.NOFOLLOW_LINKS));
    System.out.println("exists: " + Files.exists(firstPath));
    System.out.println(/* ww  w .  j  ava2  s  . c  o  m*/
            "notExists (Do not follow links): " + Files.notExists(firstPath, LinkOption.NOFOLLOW_LINKS));
    System.out.println("notExists: " + Files.notExists(firstPath));

}