List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:Main.java
public static void main(String[] args) { Path startDir = Paths.get(""); FileVisitor<Path> visitor = getFileVisitor(); try {/*from w ww . j av a2 s. c om*/ Files.walkFileTree(startDir, visitor); } catch (IOException e) { e.printStackTrace(); } }
From source file:Test.java
public static void main(String[] args) { try (BufferedReader inputReader = Files.newBufferedReader(Paths.get(new URI("file:///C:/users.txt")), Charset.defaultCharset()); BufferedWriter outputWriter = Files.newBufferedWriter(Paths.get(new URI("file:///C:/users.bak")), Charset.defaultCharset())) { String inputLine;//from www .ja v a2s . co m while ((inputLine = inputReader.readLine()) != null) { outputWriter.write(inputLine); outputWriter.newLine(); } System.out.println("Copy complete!"); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } }
From source file:Test.java
public static void main(String[] args) { try (BufferedReader inputReader = Files.newBufferedReader(Paths.get(new URI("file:///C:/users.txt")), Charset.defaultCharset()); BufferedWriter outputWriter = Files.newBufferedWriter(Paths.get(new URI("file:///C:/users.bak")), Charset.defaultCharset())) { String inputLine;//from www. j av a 2s. c o m while ((inputLine = inputReader.readLine()) != null) { outputWriter.write(inputLine); outputWriter.newLine(); } System.out.println("Copy complete!"); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String scriptFileName = "c:/test.js"; Path scriptPath = Paths.get(scriptFileName); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); try {//from w ww .j a v a2 s .c om Reader scriptReader = Files.newBufferedReader(scriptPath); engine.eval(scriptReader); } catch (IOException | ScriptException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); try {//from w w w .j a v a 2 s.c o m BasicFileAttributeView bfv = Files.getFileAttributeView(path, BasicFileAttributeView.class); BasicFileAttributes bfa = bfv.readAttributes(); 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()); FileTime newLastModifiedTime = null; FileTime newLastAccessTime = null; FileTime newCreateTime = FileTime.from(Instant.now()); bfv.setTimes(newLastModifiedTime, newLastAccessTime, newCreateTime); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("test.txt"); try (AsynchronousFileChannel afc = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) { int fileSize = (int) afc.size(); ByteBuffer dataBuffer = ByteBuffer.allocate(fileSize); Future<Integer> result = afc.read(dataBuffer, 0); int readBytes = result.get(); System.out.format("%s bytes read from %s%n", readBytes, path); System.out.format("Read data is:%n"); byte[] byteData = dataBuffer.array(); Charset cs = Charset.forName("UTF-8"); String data = new String(byteData, cs); System.out.println(data); } catch (IOException ex) { ex.printStackTrace();/* w ww .ja va 2s . c o m*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class); if (aclView == null) { System.out.format("ACL view is not supported.%n"); return;//from w w w .j a v a 2s .c o m } List<AclEntry> aclEntries = aclView.getAcl(); for (AclEntry entry : aclEntries) { System.out.format("Principal: %s%n", entry.principal()); System.out.format("Type: %s%n", entry.type()); System.out.format("Permissions are:%n"); Set<AclEntryPermission> permissions = entry.permissions(); for (AclEntryPermission p : permissions) { System.out.format("%s %n", p); } } }
From source file:Main.java
public static void main(String[] args) throws IOException { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); Path path = Paths.get("c:/"); Files.setOwner(path, lookupService.lookupPrincipalByName("joe")); }
From source file:Main.java
public static void main(String[] args) { List<String> texts = new ArrayList<>(); texts.add("test"); texts.add("test"); Path dest = Paths.get("twinkle.txt"); Charset cs = Charset.forName("US-ASCII"); try {/*from w ww.j a va 2 s. c om*/ Path p = Files.write(dest, texts, cs, StandardOpenOption.WRITE, StandardOpenOption.CREATE); System.out.println("Text was written to " + p.toAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("test.txt"); AsynchronousFileChannel afc = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE); WriteHandler handler = new WriteHandler(); ByteBuffer dataBuffer = getDataBuffer(); Attachment attach = new Attachment(); attach.asyncChannel = afc;//from w w w .ja va 2 s .c o m attach.buffer = dataBuffer; attach.path = path; afc.write(dataBuffer, 0, attach, handler); System.out.println("Sleeping for 5 seconds..."); Thread.sleep(5000); }