2828
2929package java .io ;
3030
31+ import java .net .MalformedURLException ;
3132import java .net .URI ;
3233import java .net .URISyntaxException ;
34+ import java .net .URL ;
3335import java .nio .file .FileSystems ;
3436import java .nio .file .Path ;
3537import java .security .AccessControlException ;
@@ -644,66 +646,66 @@ private static String slashify(String path, boolean isDirectory) {
644646 return p ;
645647 }
646648
647- // /**
648- // * Converts this abstract pathname into a <code>file:</code> URL. The
649- // * exact form of the URL is system-dependent. If it can be determined that
650- // * the file denoted by this abstract pathname is a directory, then the
651- // * resulting URL will end with a slash.
652- // *
653- // * @return A URL object representing the equivalent file URL
654- // *
655- // * @throws MalformedURLException
656- // * If the path cannot be parsed as a URL
657- // *
658- // * @see #toURI()
659- // * @see java.net.URI
660- // * @see java.net.URI#toURL()
661- // * @see java.net.URL
662- // * @since 1.2
663- // *
664- // * @deprecated This method does not automatically escape characters that
665- // * are illegal in URLs. It is recommended that new code convert an
666- // * abstract pathname into a URL by first converting it into a URI, via the
667- // * {@link #toURI() toURI} method, and then converting the URI into a URL
668- // * via the {@link java.net.URI#toURL() URI.toURL} method.
669- // */
670- // @Deprecated
671- // public URL toURL() throws MalformedURLException {
672- // return new URL("file", "", slashify(getAbsolutePath(), isDirectory() ));
673- // }
674- //
675- // /**
676- // * Constructs a <tt>file:</tt> URI that represents this abstract pathname.
677- // *
678- // * <p> The exact form of the URI is system-dependent. If it can be
679- // * determined that the file denoted by this abstract pathname is a
680- // * directory, then the resulting URI will end with a slash.
681- // *
682- // * <p> For a given abstract pathname <i>f</i>, it is guaranteed that
683- // *
684- // * <blockquote><tt>
685- // * new {@link #File(java.net.URI) File}(</tt><i> f</i><tt>.toURI()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
686- // * </tt></blockquote>
687- // *
688- // * so long as the original abstract pathname, the URI, and the new abstract
689- // * pathname are all created in (possibly different invocations of) the same
690- // * Java virtual machine. Due to the system-dependent nature of abstract
691- // * pathnames, however, this relationship typically does not hold when a
692- // * <tt>file:</tt> URI that is created in a virtual machine on one operating
693- // * system is converted into an abstract pathname in a virtual machine on a
694- // * different operating system.
695- // *
696- // * @return An absolute, hierarchical URI with a scheme equal to
697- // * <tt>"file"</tt>, a path representing this abstract pathname,
698- // * and undefined authority, query, and fragment components
699- // * @throws SecurityException If a required system property value cannot
700- // * be accessed.
701- // *
702- // * @see #File(java.net.URI)
703- // * @see java.net.URI
704- // * @see java.net.URI#toURL()
705- // * @since 1.4
706- // */
649+ /**
650+ * Converts this abstract pathname into a <code>file:</code> URL. The
651+ * exact form of the URL is system-dependent. If it can be determined that
652+ * the file denoted by this abstract pathname is a directory, then the
653+ * resulting URL will end with a slash.
654+ *
655+ * @return A URL object representing the equivalent file URL
656+ *
657+ * @throws MalformedURLException
658+ * If the path cannot be parsed as a URL
659+ *
660+ * @see #toURI()
661+ * @see java.net.URI
662+ * @see java.net.URI#toURL()
663+ * @see java.net.URL
664+ * @since 1.2
665+ *
666+ * @deprecated This method does not automatically escape characters that
667+ * are illegal in URLs. It is recommended that new code convert an
668+ * abstract pathname into a URL by first converting it into a URI, via the
669+ * {@link #toURI() toURI} method, and then converting the URI into a URL
670+ * via the {@link java.net.URI#toURL() URI.toURL} method.
671+ */
672+ @ Deprecated
673+ public URL toURL () throws MalformedURLException {
674+ return new URL ("file" , "" , slashify (getAbsolutePath (), false ));
675+ }
676+
677+ /**
678+ * Constructs a <tt>file:</tt> URI that represents this abstract pathname.
679+ *
680+ * <p> The exact form of the URI is system-dependent. If it can be
681+ * determined that the file denoted by this abstract pathname is a
682+ * directory, then the resulting URI will end with a slash.
683+ *
684+ * <p> For a given abstract pathname <i>f</i>, it is guaranteed that
685+ *
686+ * <blockquote><tt>
687+ * new {@link #File(java.net.URI) File}(</tt><i> f</i><tt>.toURI()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
688+ * </tt></blockquote>
689+ *
690+ * so long as the original abstract pathname, the URI, and the new abstract
691+ * pathname are all created in (possibly different invocations of) the same
692+ * Java virtual machine. Due to the system-dependent nature of abstract
693+ * pathnames, however, this relationship typically does not hold when a
694+ * <tt>file:</tt> URI that is created in a virtual machine on one operating
695+ * system is converted into an abstract pathname in a virtual machine on a
696+ * different operating system.
697+ *
698+ * @return An absolute, hierarchical URI with a scheme equal to
699+ * <tt>"file"</tt>, a path representing this abstract pathname,
700+ * and undefined authority, query, and fragment components
701+ * @throws SecurityException If a required system property value cannot
702+ * be accessed.
703+ *
704+ * @see #File(java.net.URI)
705+ * @see java.net.URI
706+ * @see java.net.URI#toURL()
707+ * @since 1.4
708+ */
707709 public URI toURI () {
708710 try {
709711 String sp = slashify (getAbsoluteFile ().getPath (), false );
@@ -779,7 +781,7 @@ public boolean canWrite() {
779781 * method denies read access to the file or directory
780782 */
781783 public boolean exists () {
782- return fs ._exists (this );
784+ return this . path . indexOf ( "!/" ) < 0 && fs ._exists (this );
783785 }
784786
785787 /**
@@ -800,7 +802,7 @@ public boolean isDirectory() {
800802// if (security != null) {
801803// security.checkRead(path);
802804// }
803- return fs ._isDir (this );
805+ return this . path . indexOf ( "!/" ) < 0 && fs ._isDir (this );
804806//
805807// return false;
806808// // BH 2019.09.23 return true;
0 commit comments