src/share/classes/java/nio/file/DirectoryStream.java

Print this page

        

*** 52,62 **** * resources associated with the stream. Failure to close the stream may result * in a resource leak. The try-with-resources statement provides a useful * construct to ensure that the stream is closed: * <pre> * Path dir = ... ! * try (DirectoryStream&lt;Path&gt; stream = dir.newDirectoryStream()) { * for (Path entry: stream) { * ... * } * } * </pre> --- 52,62 ---- * resources associated with the stream. Failure to close the stream may result * in a resource leak. The try-with-resources statement provides a useful * construct to ensure that the stream is closed: * <pre> * Path dir = ... ! * try (DirectoryStream&lt;Path&gt; stream = Files.newDirectoryStream(dir)) { * for (Path entry: stream) { * ... * } * } * </pre>
*** 95,106 **** * <p> <b>Usage Examples:</b> * Suppose we want a list of the source files in a directory. This example uses * both the for-each and try-with-resources constructs. * <pre> * List&lt;Path&gt; listSourceFiles(Path dir) throws IOException { ! * List&lt;Path&gt; result = new ArrayList&lt;Path&gt;(); ! * try (DirectoryStream&lt;Path&gt; stream = dir.newDirectoryStream("*.{c,h,cpp,hpp,java}")) { * for (Path entry: stream) { * result.add(entry); * } * } catch (DirectoryIteratorException ex) { * // I/O error encounted during the iteration, the cause is an IOException --- 95,106 ---- * <p> <b>Usage Examples:</b> * Suppose we want a list of the source files in a directory. This example uses * both the for-each and try-with-resources constructs. * <pre> * List&lt;Path&gt; listSourceFiles(Path dir) throws IOException { ! * List&lt;Path&gt; result = new ArrayList&lt;&gt;(); ! * try (DirectoryStream&lt;Path&gt; stream = Files.newDirectoryStream(dir, "*.{c,h,cpp,hpp,java}")) { * for (Path entry: stream) { * result.add(entry); * } * } catch (DirectoryIteratorException ex) { * // I/O error encounted during the iteration, the cause is an IOException
*** 111,132 **** * </pre> * @param <T> The type of element returned by the iterator * * @since 1.7 * ! * @see Path#newDirectoryStream */ public interface DirectoryStream<T> extends Closeable, Iterable<T> { /** * An interface that is implemented by objects that decide if a directory * entry should be accepted or filtered. A {@code Filter} is passed as the ! * parameter to the {@link Path#newDirectoryStream(DirectoryStream.Filter) ! * newDirectoryStream} method when opening a directory to iterate over the ! * entries in the directory. * * @param <T> the type of the directory entry * * @since 1.7 */ --- 111,132 ---- * </pre> * @param <T> The type of element returned by the iterator * * @since 1.7 * ! * @see Files#newDirectoryStream(Path) */ public interface DirectoryStream<T> extends Closeable, Iterable<T> { /** * An interface that is implemented by objects that decide if a directory * entry should be accepted or filtered. A {@code Filter} is passed as the ! * parameter to the {@link Files#newDirectoryStream(Path,DirectoryStream.Filter)} ! * method when opening a directory to iterate over the entries in the ! * directory. * * @param <T> the type of the directory entry * * @since 1.7 */