635 * <p> If this path was created by invoking the {@code File} {@link
636 * File#toPath toPath} method then there is no guarantee that the {@code
637 * File} object returned by this method is {@link #equals equal} to the
638 * original {@code File}.
639 *
640 * @implSpec
641 * The default implementation is equivalent for this path to:
642 * <pre>{@code
643 * new File(toString());
644 * }</pre>
645 * if the {@code FileSystem} which created this {@code Path} is the default
646 * file system; otherwise an {@code UnsupportedOperationException} is
647 * thrown.
648 *
649 * @return a {@code File} object representing this path
650 *
651 * @throws UnsupportedOperationException
652 * if this {@code Path} is not associated with the default provider
653 */
654 default File toFile() {
655 if (getFileSystem() == FileSystems.getDefault()) {
656 return new File(toString());
657 } else {
658 throw new UnsupportedOperationException("Path not associated with "
659 + "default file system.");
660 }
661 }
662
663 // -- watchable --
664
665 /**
666 * Registers the file located by this path with a watch service.
667 *
668 * <p> In this release, this path locates a directory that exists. The
669 * directory is registered with the watch service so that entries in the
670 * directory can be watched. The {@code events} parameter is the events to
671 * register and may contain the following events:
672 * <ul>
673 * <li>{@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE} -
674 * entry created or moved into the directory</li>
675 * <li>{@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE} -
|
635 * <p> If this path was created by invoking the {@code File} {@link
636 * File#toPath toPath} method then there is no guarantee that the {@code
637 * File} object returned by this method is {@link #equals equal} to the
638 * original {@code File}.
639 *
640 * @implSpec
641 * The default implementation is equivalent for this path to:
642 * <pre>{@code
643 * new File(toString());
644 * }</pre>
645 * if the {@code FileSystem} which created this {@code Path} is the default
646 * file system; otherwise an {@code UnsupportedOperationException} is
647 * thrown.
648 *
649 * @return a {@code File} object representing this path
650 *
651 * @throws UnsupportedOperationException
652 * if this {@code Path} is not associated with the default provider
653 */
654 default File toFile() {
655 if (getFileSystem() == FileSystems.getBuiltin() ||
656 getFileSystem() == FileSystems.getDefault()) {
657 return new File(toString());
658 } else {
659 throw new UnsupportedOperationException("Path not associated with "
660 + "default file system.");
661 }
662 }
663
664 // -- watchable --
665
666 /**
667 * Registers the file located by this path with a watch service.
668 *
669 * <p> In this release, this path locates a directory that exists. The
670 * directory is registered with the watch service so that entries in the
671 * directory can be watched. The {@code events} parameter is the events to
672 * register and may contain the following events:
673 * <ul>
674 * <li>{@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE} -
675 * entry created or moved into the directory</li>
676 * <li>{@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE} -
|