Example usage for java.nio.file Path getFileName

List of usage examples for java.nio.file Path getFileName

Introduction

In this page you can find the example usage for java.nio.file Path getFileName.

Prototype

Path getFileName();

Source Link

Document

Returns the name of the file or directory denoted by this path as a Path object.

Usage

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 ava  2  s.  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 w  w w .j a v  a 2s  .  c om*/
}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("C:/tutorial/Java/JavaFX");

    //no filter applyied
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
        for (Path file : ds) {
            System.out.println(file.getFileName());
        }//from www.j a v a  2  s.co  m
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {
    Path directory = Paths.get("c:/");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) {
        for (Path file : directoryStream) {
            System.out.println(file.getFileName());
        }//w  w w.ja  v  a  2  s .c  o  m
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }
}

From source file:Test.java

public static void main(String[] args) {
    Path directory = Paths.get("/home");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) {
        for (Path file : directoryStream) {
            System.out.println(file.getFileName());
        }/*  www . jav  a 2  s .c o m*/
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }
}

From source file:Test.java

public static void main(String[] args) {
    Path directory = Paths.get("C:/Program Files/Java/jdk1.7.0/bin");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, "java*.exe")) {
        for (Path file : directoryStream) {
            System.out.println(file.getFileName());
        }/*from  w  w  w  . java2  s.  c  om*/
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("C:/tutorial/Java/JavaFX");

    DirectoryStream.Filter<Path> dir_filter = new DirectoryStream.Filter<Path>() {
        public boolean accept(Path path) throws IOException {
            return (Files.isDirectory(path, NOFOLLOW_LINKS));
        }/*from  w w  w. j  a  va2 s .c  o m*/
    };

    try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, dir_filter)) {
        for (Path file : ds) {
            System.out.println(file.getFileName());
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Test.java

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

    Path listing = Paths.get("/usr/bin/zip");

    System.out.println("File Name [" + listing.getFileName() + "]");
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("create", "true");
    URI zipFile = URI.create("jar:file:/home.zip");
    try (FileSystem zipFileSys = FileSystems.newFileSystem(zipFile, attributes);) {
        Path path = zipFileSys.getPath("docs");
        Files.createDirectory(path);
        try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(zipFileSys.getPath("/"));) {
            for (Path file : directoryStream) {
                System.out.println(file.getFileName());
            }/*  w ww .  j  a  v  a  2s .co m*/
        }
    }
}

From source file:Test.java

public static void main(String[] args) {
    Path directory = Paths.get("C:/Program Files/Java/jdk1.7.0/bin");
    PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:java?.exe");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, "java*.exe")) {
        for (Path file : directoryStream) {
            if (pathMatcher.matches(file.getFileName())) {
                System.out.println(file.getFileName());
            }/* w  w w .ja va2 s.  c o m*/
        }
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }

}