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("/home/docs/users.txt");
    Map<String, Object> attrsMap = Files.readAttributes(path, "*");
    Set<String> keys = attrsMap.keySet();

    for (String attribute : keys) {
        System.out.println(attribute + ": " + Files.getAttribute(path, attribute));
    }/*from w  ww  . ja v  a2 s .  c  o m*/

}

From source file:Main.java

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

    long uniqueWords = Files.lines(Paths.get("Main.java"), Charset.defaultCharset())
            .flatMap(line -> Arrays.stream(line.split(" "))).distinct().count();

    System.out.println("There are " + uniqueWords + " unique words in data.txt");

}

From source file:Main.java

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

    System.out.println(Files.isSymbolicLink(path1));
    System.out.println(Files.isSymbolicLink(path2));

}

From source file:Test.java

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

    Path file = Paths.get("/opt/platform/java");
    if (Files.isSymbolicLink(file)) {
        file = Files.readSymbolicLink(file);
    }//from w w w .j  a v a 2s.c o m
    Files.readAttributes(file, BasicFileAttributes.class);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Path path = Paths.get("E:\\Java_Dev");

    List<Path> files = Files.walk(path).filter(Files::isReadable).filter(Files::isRegularFile).limit(10)
            .collect(Collectors.toList());
    System.out.println(files);// ww  w. j av  a2  s  .co m
}

From source file:Main.java

public static void main(String[] args) {
    final String dir = "C:\\data\\projects\\";
    final Path path = Paths.get(dir);
    final File file = path.toFile();
    Stream.of(file.listFiles(File::isDirectory)).forEach(System.out::println);
    ;//from   w ww  . ja  va 2  s.c o  m
}

From source file:Test.java

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

    System.out.println(Files.isSymbolicLink(path1));
    System.out.println(Files.isSymbolicLink(path2));

    Path path = Paths.get(new URI("C:/home/./music/users.txt"));
    System.out.println("Normalized: " + path.normalize());
    System.out.println("Absolute path: " + path.toAbsolutePath());
    System.out.println("URI: " + path.toUri());
    System.out.println("toRealPath (Do not follow links): " + path.toRealPath(LinkOption.NOFOLLOW_LINKS));
    System.out.println("toRealPath: " + path.toRealPath());

}

From source file:Test.java

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

    Path dir = Paths.get("C:/workspace/java");

    DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.properties");
    for (Path entry : stream) {
        System.out.println(entry.getFileName());
    }/*from   www.  j  a  va  2s .  c om*/
}

From source file:Main.java

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

    Path dir = Paths.get("C:/");

    DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.exe");
    for (Path entry : stream) {
        System.out.println(entry.getFileName());
    }//from  ww  w  .j a  v a 2  s  . co m
}

From source file:Main.java

public static void main(String[] args) {
    Path path = Paths.get("C:\\Java_Dev\\test1.txt");

    try {/*from   ww w  .  j a v  a 2 s  . c o m*/
        BasicFileAttributes bfa = Files.readAttributes(path, BasicFileAttributes.class);
        System.out.format("Size:%s bytes %n", bfa.size());
        System.out.format("Creation Time:%s %n", bfa.creationTime());
        System.out.format("Last Access  Time:%s %n", bfa.lastAccessTime());
    } catch (IOException e) {
        e.printStackTrace();
    }
}