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(String first, String... more) 

Source Link

Document

Converts a path string, or a sequence of strings that when joined form a path string, to a Path .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Files.lines(Paths.get("c:/Java_Dev", "run.bat")).filter(line -> line.startsWith("A"))
            .forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("/tutorial/Java/JavaFX", "Topic.txt");

    // convert path to "real" path
    try {//from   ww w .  j a v  a2  s  .  co  m
        Path real_path = path.toRealPath(LinkOption.NOFOLLOW_LINKS);
        System.out.println("Path to real path: " + real_path);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {

    Path wiki_path = Paths.get("C:/tutorial/wiki", "wiki.txt");

    try {/*from w w  w  .j a v  a2 s .  c o m*/
        byte[] wikiArray = Files.readAllBytes(wiki_path);

        String wikiString = new String(wikiArray, "ISO-8859-1");
        System.out.println(wikiString);
    } catch (IOException e) {
        System.out.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {

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

    BasicFileAttributeView bv = Files.getFileAttributeView(path, BasicFileAttributeView.class);
    System.out.println(bv.name());

}

From source file:Main.java

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

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

    //extract a single attribute with getAttribute
    try {//  www  .  ja v  a 2s. c  o  m
        long size = (Long) Files.getAttribute(path, "basic:size", java.nio.file.LinkOption.NOFOLLOW_LINKS);
        System.out.println("Size: " + size);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*w w  w  . j  a  va  2 s. c  o m*/
        Stream<String> lines = Files.lines(Paths.get("files", "data.csv"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    Path copy_from_4 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt");
    Path copy_to_4 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt");
    try (OutputStream os = new FileOutputStream(copy_to_4.toFile())) {

        Files.copy(copy_from_4, os);

    } catch (IOException e) {
        System.err.println(e);/* w ww . java  2s .c  om*/
    }

}

From source file:Main.java

public static void main(String[] args) {

    Path wiki_path = Paths.get("C:/tutorial/wiki", "wiki.txt");

    Charset charset = Charset.forName("UTF-8");
    try (BufferedReader reader = Files.newBufferedReader(wiki_path, charset)) {
        String line = null;/*from   w  w  w . ja  va 2 s. c o  m*/
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException e) {
        System.err.println(e);
    }
}

From source file:Main.java

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

    BasicFileAttributes attr = null;
    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

    attr = Files.readAttributes(path, BasicFileAttributes.class);

    System.out.println("File size: " + attr.size());

}

From source file:Main.java

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

    BasicFileAttributes attr = null;
    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

    attr = Files.readAttributes(path, BasicFileAttributes.class);

    System.out.println("Is other ? " + attr.isOther());

}