NIO 2 File API

From NovaOrdis Knowledge Base
Revision as of 00:40, 26 August 2020 by Ovidiu (talk | contribs) (→‎Recipes)
Jump to navigation Jump to search

External

Internal

Subjects

Recipes

Create one directory:

Path parent = ...;
Path dir = Files.createDirectory(Paths.get(parent.toString(), "my-dir"));

Create a directory hierarchy:

Path parent = ...;
Path dir = Files.createDirectories(Paths.get(parent.toString(), "dir1/dir2/dir3"));

Get file name:

Path file = ...;
String fileName = file.getFileName().toString();

Create a file with a specified content:

Path file = ...;
Files.write(file, "something".getBytes());