NIO 2 File API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 22: Line 22:
Path parent = ...;
Path parent = ...;
Path dir = Files.createDirectories(Paths.get(parent.toString(), "dir1/dir2/dir3"));
Path dir = Files.createDirectories(Paths.get(parent.toString(), "dir1/dir2/dir3"));
</syntaxhighlight>
Get file name:
<syntaxhighlight lang='java'>
Path file = ...;
String fileName = file.getFileName().toString();
</syntaxhighlight>
</syntaxhighlight>

Revision as of 07:51, 6 August 2020

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();