NIO 2 File API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 28: Line 28:
Path file = ...;
Path file = ...;
String fileName = file.getFileName().toString();
String fileName = file.getFileName().toString();
</syntaxhighlight>
Create a file with a specified content:
<syntaxhighlight lang='java'>
Path file = ...;
Files.write(file, "something".getBytes());
</syntaxhighlight>
</syntaxhighlight>

Revision as of 00:40, 26 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();

Create a file with a specified content:

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