Files.NewDirectoryStream Method

Definition

Overloads

NewDirectoryStream(IPath)

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.

NewDirectoryStream(IPath, IDirectoryStreamFilter)

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.

NewDirectoryStream(IPath, String)

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory.

NewDirectoryStream(IPath)

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.

[Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)]
public static Java.Nio.FileNio.IDirectoryStream? NewDirectoryStream (Java.Nio.FileNio.IPath? dir);
[<Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)>]
static member NewDirectoryStream : Java.Nio.FileNio.IPath -> Java.Nio.FileNio.IDirectoryStream

Parameters

dir
IPath

the path to the directory

Returns

a new and open DirectoryStream object

Attributes

Remarks

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory. The elements returned by the directory stream's DirectoryStream#iterator iterator are of type Path, each one representing an entry in the directory. The Path objects are obtained as if by Path#resolve(Path) resolving the name of the directory entry against dir.

When not using the try-with-resources construct, then directory stream's close method should be invoked after iteration is completed so as to free any resources held for the open directory.

When an implementation supports operations on entries in the directory that execute in a race-free manner then the returned directory stream is a SecureDirectoryStream.

Java documentation for java.nio.file.Files.newDirectoryStream(java.nio.file.Path).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

NewDirectoryStream(IPath, IDirectoryStreamFilter)

Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.

[Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;Ljava/nio/file/DirectoryStream$Filter;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)]
public static Java.Nio.FileNio.IDirectoryStream? NewDirectoryStream (Java.Nio.FileNio.IPath? dir, Java.Nio.FileNio.IDirectoryStreamFilter? filter);
[<Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;Ljava/nio/file/DirectoryStream$Filter;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)>]
static member NewDirectoryStream : Java.Nio.FileNio.IPath * Java.Nio.FileNio.IDirectoryStreamFilter -> Java.Nio.FileNio.IDirectoryStream

Parameters

dir
IPath

the path to the directory

Returns

a new and open DirectoryStream object

Attributes

Remarks

Java documentation for java.nio.file.Files.newDirectoryStream(java.nio.file.Path).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

NewDirectoryStream(IPath, String)

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory.

[Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;Ljava/lang/String;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)]
public static Java.Nio.FileNio.IDirectoryStream? NewDirectoryStream (Java.Nio.FileNio.IPath? dir, string? glob);
[<Android.Runtime.Register("newDirectoryStream", "(Ljava/nio/file/Path;Ljava/lang/String;)Ljava/nio/file/DirectoryStream;", "", ApiSince=26)>]
static member NewDirectoryStream : Java.Nio.FileNio.IPath * string -> Java.Nio.FileNio.IDirectoryStream

Parameters

dir
IPath

the path to the directory

glob
String

the glob pattern

Returns

a new and open DirectoryStream object

Attributes

Remarks

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory. The elements returned by the directory stream's DirectoryStream#iterator iterator are of type Path, each one representing an entry in the directory. The Path objects are obtained as if by Path#resolve(Path) resolving the name of the directory entry against dir. The entries returned by the iterator are filtered by matching the String representation of their file names against the given <em>globbing</em> pattern.

For example, suppose we want to iterate over the files ending with ".java" in a directory:

Path dir = ...
                try (DirectoryStream&lt;Path&gt; stream = Files.newDirectoryStream(dir, "*.java")) {
                    :
                }

The globbing pattern is specified by the FileSystem#getPathMatcher getPathMatcher method.

When not using the try-with-resources construct, then directory stream's close method should be invoked after iteration is completed so as to free any resources held for the open directory.

When an implementation supports operations on entries in the directory that execute in a race-free manner then the returned directory stream is a SecureDirectoryStream.

Java documentation for java.nio.file.Files.newDirectoryStream(java.nio.file.Path, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to