List of usage examples for java.nio.file Paths get
public static Path get(String first, String... more)
From source file:Main.java
public static void main(String[] args) { DosFileAttributes attr = null; Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); try {// w w w . ja v a2 s. c o m attr = Files.readAttributes(path, DosFileAttributes.class); } catch (IOException e) { System.err.println(e); } System.out.println("Is Hidden ? " + attr.isHidden()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); long time = System.currentTimeMillis(); FileTime fileTime = FileTime.fromMillis(time); try {/*from w ww . j a v a 2s .c om*/ Files.setAttribute(path, "basic:lastModifiedTime", fileTime, LinkOption.NOFOLLOW_LINKS); Files.setAttribute(path, "basic:creationTime", fileTime, LinkOption.NOFOLLOW_LINKS); Files.setAttribute(path, "basic:lastAccessTime", fileTime, LinkOption.NOFOLLOW_LINKS); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); long time = System.currentTimeMillis(); FileTime fileTime = FileTime.fromMillis(time); try {/* w w w . j av a 2 s . co m*/ BasicFileAttributeView bv = Files.getFileAttributeView(path, BasicFileAttributeView.class); bv.setTimes(fileTime, fileTime, fileTime); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path rn_demo = Paths.get("C:/tutorial/Java", "demo.txt"); //using NIO.2 unbuffered stream int n;// w w w . j a va 2s .c om try (InputStream in = Files.newInputStream(rn_demo)) { while ((n = in.read()) != -1) { System.out.print((char) n); } } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path ball_path = Paths.get("C:/tutorial/photos", "ball.png"); byte[] ball_bytes = new byte[] { (byte) 0x89, (byte) 0x50, (byte) 0x4e, }; try {/*from w w w . j ava 2 s. c o m*/ Files.write(ball_path, ball_bytes); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); try {/*w w w .jav a 2 s . c om*/ BasicFileAttributeView bv = Files.getFileAttributeView(path, BasicFileAttributeView.class); BasicFileAttributes ba = bv.readAttributes(); System.out.println(ba.creationTime()); } 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"); Charset charset = Charset.forName("UTF-8"); String text = "\nfrom java2s.com!"; try (BufferedWriter writer = Files.newBufferedWriter(wiki_path, charset, StandardOpenOption.APPEND)) { writer.write(text);/*from w ww . ja v a 2s.co m*/ } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path myText_path = Paths.get("C:/tutorial/wiki", "wiki.txt"); Charset charset = Charset.forName("UTF-8"); ArrayList<String> lines = new ArrayList<>(); lines.add("\n"); lines.add("tutorial"); try {/*from w w w .j av a 2 s .c o m*/ Files.write(myText_path, lines, charset, StandardOpenOption.APPEND); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) { Path copy_from_2 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt"); Path copy_to_2 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt"); try (InputStream is = new FileInputStream(copy_from_2.toFile())) { Files.copy(is, copy_to_2, REPLACE_EXISTING); } catch (IOException e) { System.err.println(e);/*from w w w. j a v a 2 s .c om*/ } }
From source file:Main.java
public static void main(String[] args) { Path rn_demo = Paths.get("C:/tutorial/Java", "demo.txt"); String demo = "tutorial"; String string = "\nString: from java2s.com"; //using NIO.2 unbuffered stream byte data[] = demo.getBytes(); try (OutputStream outputStream = Files.newOutputStream(rn_demo)) { outputStream.write(data);//ww w.j a va 2 s . co m } catch (IOException e) { System.err.println(e); } }