src/java.base/share/classes/java/io/File.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54441 03ea2b6428f0
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    44  * abstract, system-independent view of hierarchical pathnames.  An
    44  * abstract, system-independent view of hierarchical pathnames.  An
    45  * <em>abstract pathname</em> has two components:
    45  * <em>abstract pathname</em> has two components:
    46  *
    46  *
    47  * <ol>
    47  * <ol>
    48  * <li> An optional system-dependent <em>prefix</em> string,
    48  * <li> An optional system-dependent <em>prefix</em> string,
    49  *      such as a disk-drive specifier, <code>"/"</code>&nbsp;for the UNIX root
    49  *      such as a disk-drive specifier, {@code "/"}&nbsp;for the UNIX root
    50  *      directory, or <code>"\\\\"</code>&nbsp;for a Microsoft Windows UNC pathname, and
    50  *      directory, or {@code "\\\\"}&nbsp;for a Microsoft Windows UNC pathname, and
    51  * <li> A sequence of zero or more string <em>names</em>.
    51  * <li> A sequence of zero or more string <em>names</em>.
    52  * </ol>
    52  * </ol>
    53  *
    53  *
    54  * The first name in an abstract pathname may be a directory name or, in the
    54  * The first name in an abstract pathname may be a directory name or, in the
    55  * case of Microsoft Windows UNC pathnames, a hostname.  Each subsequent name
    55  * case of Microsoft Windows UNC pathnames, a hostname.  Each subsequent name
    59  *
    59  *
    60  * <p> The conversion of a pathname string to or from an abstract pathname is
    60  * <p> The conversion of a pathname string to or from an abstract pathname is
    61  * inherently system-dependent.  When an abstract pathname is converted into a
    61  * inherently system-dependent.  When an abstract pathname is converted into a
    62  * pathname string, each name is separated from the next by a single copy of
    62  * pathname string, each name is separated from the next by a single copy of
    63  * the default <em>separator character</em>.  The default name-separator
    63  * the default <em>separator character</em>.  The default name-separator
    64  * character is defined by the system property <code>file.separator</code>, and
    64  * character is defined by the system property {@code file.separator}, and
    65  * is made available in the public static fields {@link
    65  * is made available in the public static fields {@link
    66  * #separator} and {@link #separatorChar} of this class.
    66  * #separator} and {@link #separatorChar} of this class.
    67  * When a pathname string is converted into an abstract pathname, the names
    67  * When a pathname string is converted into an abstract pathname, the names
    68  * within it may be separated by the default name-separator character or by any
    68  * within it may be separated by the default name-separator character or by any
    69  * other name-separator character that is supported by the underlying system.
    69  * other name-separator character that is supported by the underlying system.
    71  * <p> A pathname, whether abstract or in string form, may be either
    71  * <p> A pathname, whether abstract or in string form, may be either
    72  * <em>absolute</em> or <em>relative</em>.  An absolute pathname is complete in
    72  * <em>absolute</em> or <em>relative</em>.  An absolute pathname is complete in
    73  * that no other information is required in order to locate the file that it
    73  * that no other information is required in order to locate the file that it
    74  * denotes.  A relative pathname, in contrast, must be interpreted in terms of
    74  * denotes.  A relative pathname, in contrast, must be interpreted in terms of
    75  * information taken from some other pathname.  By default the classes in the
    75  * information taken from some other pathname.  By default the classes in the
    76  * <code>java.io</code> package always resolve relative pathnames against the
    76  * {@code java.io} package always resolve relative pathnames against the
    77  * current user directory.  This directory is named by the system property
    77  * current user directory.  This directory is named by the system property
    78  * <code>user.dir</code>, and is typically the directory in which the Java
    78  * {@code user.dir}, and is typically the directory in which the Java
    79  * virtual machine was invoked.
    79  * virtual machine was invoked.
    80  *
    80  *
    81  * <p> The <em>parent</em> of an abstract pathname may be obtained by invoking
    81  * <p> The <em>parent</em> of an abstract pathname may be obtained by invoking
    82  * the {@link #getParent} method of this class and consists of the pathname's
    82  * the {@link #getParent} method of this class and consists of the pathname's
    83  * prefix and each name in the pathname's name sequence except for the last.
    83  * prefix and each name in the pathname's name sequence except for the last.
    92  * as follows:
    92  * as follows:
    93  *
    93  *
    94  * <ul>
    94  * <ul>
    95  *
    95  *
    96  * <li> For UNIX platforms, the prefix of an absolute pathname is always
    96  * <li> For UNIX platforms, the prefix of an absolute pathname is always
    97  * <code>"/"</code>.  Relative pathnames have no prefix.  The abstract pathname
    97  * {@code "/"}.  Relative pathnames have no prefix.  The abstract pathname
    98  * denoting the root directory has the prefix <code>"/"</code> and an empty
    98  * denoting the root directory has the prefix {@code "/"} and an empty
    99  * name sequence.
    99  * name sequence.
   100  *
   100  *
   101  * <li> For Microsoft Windows platforms, the prefix of a pathname that contains a drive
   101  * <li> For Microsoft Windows platforms, the prefix of a pathname that contains a drive
   102  * specifier consists of the drive letter followed by <code>":"</code> and
   102  * specifier consists of the drive letter followed by {@code ":"} and
   103  * possibly followed by <code>"\\"</code> if the pathname is absolute.  The
   103  * possibly followed by {@code "\\"} if the pathname is absolute.  The
   104  * prefix of a UNC pathname is <code>"\\\\"</code>; the hostname and the share
   104  * prefix of a UNC pathname is {@code "\\\\"}; the hostname and the share
   105  * name are the first two names in the name sequence.  A relative pathname that
   105  * name are the first two names in the name sequence.  A relative pathname that
   106  * does not specify a drive has no prefix.
   106  * does not specify a drive has no prefix.
   107  *
   107  *
   108  * </ul>
   108  * </ul>
   109  *
   109  *
   122  * system may have multiple sets of access permissions on a single object.
   122  * system may have multiple sets of access permissions on a single object.
   123  * For example, one set may apply to the object's <i>owner</i>, and another
   123  * For example, one set may apply to the object's <i>owner</i>, and another
   124  * may apply to all other users.  The access permissions on an object may
   124  * may apply to all other users.  The access permissions on an object may
   125  * cause some methods in this class to fail.
   125  * cause some methods in this class to fail.
   126  *
   126  *
   127  * <p> Instances of the <code>File</code> class are immutable; that is, once
   127  * <p> Instances of the {@code File} class are immutable; that is, once
   128  * created, the abstract pathname represented by a <code>File</code> object
   128  * created, the abstract pathname represented by a {@code File} object
   129  * will never change.
   129  * will never change.
   130  *
   130  *
   131  * <h2>Interoperability with {@code java.nio.file} package</h2>
   131  * <h2>Interoperability with {@code java.nio.file} package</h2>
   132  *
   132  *
   133  * <p> The <a href="../../java/nio/file/package-summary.html">{@code java.nio.file}</a>
   133  * <p> The <a href="../../java/nio/file/package-summary.html">{@code java.nio.file}</a>
   180      * returning false does not guarantee that the path is valid.
   180      * returning false does not guarantee that the path is valid.
   181      *
   181      *
   182      * @return true if the file path is invalid.
   182      * @return true if the file path is invalid.
   183      */
   183      */
   184     final boolean isInvalid() {
   184     final boolean isInvalid() {
   185         if (status == null) {
   185         PathStatus s = status;
   186             status = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
   186         if (s == null) {
   187                                                        : PathStatus.INVALID;
   187             s = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED
   188         }
   188                                                   : PathStatus.INVALID;
   189         return status == PathStatus.INVALID;
   189             status = s;
       
   190         }
       
   191         return s == PathStatus.INVALID;
   190     }
   192     }
   191 
   193 
   192     /**
   194     /**
   193      * The length of this abstract pathname's prefix, or zero if it has no
   195      * The length of this abstract pathname's prefix, or zero if it has no
   194      * prefix.
   196      * prefix.
   204     }
   206     }
   205 
   207 
   206     /**
   208     /**
   207      * The system-dependent default name-separator character.  This field is
   209      * The system-dependent default name-separator character.  This field is
   208      * initialized to contain the first character of the value of the system
   210      * initialized to contain the first character of the value of the system
   209      * property <code>file.separator</code>.  On UNIX systems the value of this
   211      * property {@code file.separator}.  On UNIX systems the value of this
   210      * field is <code>'/'</code>; on Microsoft Windows systems it is <code>'\\'</code>.
   212      * field is {@code '/'}; on Microsoft Windows systems it is {@code '\\'}.
   211      *
   213      *
   212      * @see     java.lang.System#getProperty(java.lang.String)
   214      * @see     java.lang.System#getProperty(java.lang.String)
   213      */
   215      */
   214     public static final char separatorChar = fs.getSeparator();
   216     public static final char separatorChar = fs.getSeparator();
   215 
   217 
   221     public static final String separator = "" + separatorChar;
   223     public static final String separator = "" + separatorChar;
   222 
   224 
   223     /**
   225     /**
   224      * The system-dependent path-separator character.  This field is
   226      * The system-dependent path-separator character.  This field is
   225      * initialized to contain the first character of the value of the system
   227      * initialized to contain the first character of the value of the system
   226      * property <code>path.separator</code>.  This character is used to
   228      * property {@code path.separator}.  This character is used to
   227      * separate filenames in a sequence of files given as a <em>path list</em>.
   229      * separate filenames in a sequence of files given as a <em>path list</em>.
   228      * On UNIX systems, this character is <code>':'</code>; on Microsoft Windows systems it
   230      * On UNIX systems, this character is {@code ':'}; on Microsoft Windows systems it
   229      * is <code>';'</code>.
   231      * is {@code ';'}.
   230      *
   232      *
   231      * @see     java.lang.System#getProperty(java.lang.String)
   233      * @see     java.lang.System#getProperty(java.lang.String)
   232      */
   234      */
   233     public static final char pathSeparatorChar = fs.getPathSeparator();
   235     public static final char pathSeparatorChar = fs.getPathSeparator();
   234 
   236 
   261         this.path = fs.resolve(parent.path, child);
   263         this.path = fs.resolve(parent.path, child);
   262         this.prefixLength = parent.prefixLength;
   264         this.prefixLength = parent.prefixLength;
   263     }
   265     }
   264 
   266 
   265     /**
   267     /**
   266      * Creates a new <code>File</code> instance by converting the given
   268      * Creates a new {@code File} instance by converting the given
   267      * pathname string into an abstract pathname.  If the given string is
   269      * pathname string into an abstract pathname.  If the given string is
   268      * the empty string, then the result is the empty abstract pathname.
   270      * the empty string, then the result is the empty abstract pathname.
   269      *
   271      *
   270      * @param   pathname  A pathname string
   272      * @param   pathname  A pathname string
   271      * @throws  NullPointerException
   273      * @throws  NullPointerException
   272      *          If the <code>pathname</code> argument is <code>null</code>
   274      *          If the {@code pathname} argument is {@code null}
   273      */
   275      */
   274     public File(String pathname) {
   276     public File(String pathname) {
   275         if (pathname == null) {
   277         if (pathname == null) {
   276             throw new NullPointerException();
   278             throw new NullPointerException();
   277         }
   279         }
   285        directory defined by the FileSystem.getDefaultParent method.  On Unix
   287        directory defined by the FileSystem.getDefaultParent method.  On Unix
   286        this default is "/", while on Microsoft Windows it is "\\".  This is required for
   288        this default is "/", while on Microsoft Windows it is "\\".  This is required for
   287        compatibility with the original behavior of this class. */
   289        compatibility with the original behavior of this class. */
   288 
   290 
   289     /**
   291     /**
   290      * Creates a new <code>File</code> instance from a parent pathname string
   292      * Creates a new {@code File} instance from a parent pathname string
   291      * and a child pathname string.
   293      * and a child pathname string.
   292      *
   294      *
   293      * <p> If <code>parent</code> is <code>null</code> then the new
   295      * <p> If {@code parent} is {@code null} then the new
   294      * <code>File</code> instance is created as if by invoking the
   296      * {@code File} instance is created as if by invoking the
   295      * single-argument <code>File</code> constructor on the given
   297      * single-argument {@code File} constructor on the given
   296      * <code>child</code> pathname string.
   298      * {@code child} pathname string.
   297      *
   299      *
   298      * <p> Otherwise the <code>parent</code> pathname string is taken to denote
   300      * <p> Otherwise the {@code parent} pathname string is taken to denote
   299      * a directory, and the <code>child</code> pathname string is taken to
   301      * a directory, and the {@code child} pathname string is taken to
   300      * denote either a directory or a file.  If the <code>child</code> pathname
   302      * denote either a directory or a file.  If the {@code child} pathname
   301      * string is absolute then it is converted into a relative pathname in a
   303      * string is absolute then it is converted into a relative pathname in a
   302      * system-dependent way.  If <code>parent</code> is the empty string then
   304      * system-dependent way.  If {@code parent} is the empty string then
   303      * the new <code>File</code> instance is created by converting
   305      * the new {@code File} instance is created by converting
   304      * <code>child</code> into an abstract pathname and resolving the result
   306      * {@code child} into an abstract pathname and resolving the result
   305      * against a system-dependent default directory.  Otherwise each pathname
   307      * against a system-dependent default directory.  Otherwise each pathname
   306      * string is converted into an abstract pathname and the child abstract
   308      * string is converted into an abstract pathname and the child abstract
   307      * pathname is resolved against the parent.
   309      * pathname is resolved against the parent.
   308      *
   310      *
   309      * @param   parent  The parent pathname string
   311      * @param   parent  The parent pathname string
   310      * @param   child   The child pathname string
   312      * @param   child   The child pathname string
   311      * @throws  NullPointerException
   313      * @throws  NullPointerException
   312      *          If <code>child</code> is <code>null</code>
   314      *          If {@code child} is {@code null}
   313      */
   315      */
   314     public File(String parent, String child) {
   316     public File(String parent, String child) {
   315         if (child == null) {
   317         if (child == null) {
   316             throw new NullPointerException();
   318             throw new NullPointerException();
   317         }
   319         }
   328         }
   330         }
   329         this.prefixLength = fs.prefixLength(this.path);
   331         this.prefixLength = fs.prefixLength(this.path);
   330     }
   332     }
   331 
   333 
   332     /**
   334     /**
   333      * Creates a new <code>File</code> instance from a parent abstract
   335      * Creates a new {@code File} instance from a parent abstract
   334      * pathname and a child pathname string.
   336      * pathname and a child pathname string.
   335      *
   337      *
   336      * <p> If <code>parent</code> is <code>null</code> then the new
   338      * <p> If {@code parent} is {@code null} then the new
   337      * <code>File</code> instance is created as if by invoking the
   339      * {@code File} instance is created as if by invoking the
   338      * single-argument <code>File</code> constructor on the given
   340      * single-argument {@code File} constructor on the given
   339      * <code>child</code> pathname string.
   341      * {@code child} pathname string.
   340      *
   342      *
   341      * <p> Otherwise the <code>parent</code> abstract pathname is taken to
   343      * <p> Otherwise the {@code parent} abstract pathname is taken to
   342      * denote a directory, and the <code>child</code> pathname string is taken
   344      * denote a directory, and the {@code child} pathname string is taken
   343      * to denote either a directory or a file.  If the <code>child</code>
   345      * to denote either a directory or a file.  If the {@code child}
   344      * pathname string is absolute then it is converted into a relative
   346      * pathname string is absolute then it is converted into a relative
   345      * pathname in a system-dependent way.  If <code>parent</code> is the empty
   347      * pathname in a system-dependent way.  If {@code parent} is the empty
   346      * abstract pathname then the new <code>File</code> instance is created by
   348      * abstract pathname then the new {@code File} instance is created by
   347      * converting <code>child</code> into an abstract pathname and resolving
   349      * converting {@code child} into an abstract pathname and resolving
   348      * the result against a system-dependent default directory.  Otherwise each
   350      * the result against a system-dependent default directory.  Otherwise each
   349      * pathname string is converted into an abstract pathname and the child
   351      * pathname string is converted into an abstract pathname and the child
   350      * abstract pathname is resolved against the parent.
   352      * abstract pathname is resolved against the parent.
   351      *
   353      *
   352      * @param   parent  The parent abstract pathname
   354      * @param   parent  The parent abstract pathname
   353      * @param   child   The child pathname string
   355      * @param   child   The child pathname string
   354      * @throws  NullPointerException
   356      * @throws  NullPointerException
   355      *          If <code>child</code> is <code>null</code>
   357      *          If {@code child} is {@code null}
   356      */
   358      */
   357     public File(File parent, String child) {
   359     public File(File parent, String child) {
   358         if (child == null) {
   360         if (child == null) {
   359             throw new NullPointerException();
   361             throw new NullPointerException();
   360         }
   362         }
   456         return path.substring(index + 1);
   458         return path.substring(index + 1);
   457     }
   459     }
   458 
   460 
   459     /**
   461     /**
   460      * Returns the pathname string of this abstract pathname's parent, or
   462      * Returns the pathname string of this abstract pathname's parent, or
   461      * <code>null</code> if this pathname does not name a parent directory.
   463      * {@code null} if this pathname does not name a parent directory.
   462      *
   464      *
   463      * <p> The <em>parent</em> of an abstract pathname consists of the
   465      * <p> The <em>parent</em> of an abstract pathname consists of the
   464      * pathname's prefix, if any, and each name in the pathname's name
   466      * pathname's prefix, if any, and each name in the pathname's name
   465      * sequence except for the last.  If the name sequence is empty then
   467      * sequence except for the last.  If the name sequence is empty then
   466      * the pathname does not name a parent directory.
   468      * the pathname does not name a parent directory.
   467      *
   469      *
   468      * @return  The pathname string of the parent directory named by this
   470      * @return  The pathname string of the parent directory named by this
   469      *          abstract pathname, or <code>null</code> if this pathname
   471      *          abstract pathname, or {@code null} if this pathname
   470      *          does not name a parent
   472      *          does not name a parent
   471      */
   473      */
   472     public String getParent() {
   474     public String getParent() {
   473         int index = path.lastIndexOf(separatorChar);
   475         int index = path.lastIndexOf(separatorChar);
   474         if (index < prefixLength) {
   476         if (index < prefixLength) {
   479         return path.substring(0, index);
   481         return path.substring(0, index);
   480     }
   482     }
   481 
   483 
   482     /**
   484     /**
   483      * Returns the abstract pathname of this abstract pathname's parent,
   485      * Returns the abstract pathname of this abstract pathname's parent,
   484      * or <code>null</code> if this pathname does not name a parent
   486      * or {@code null} if this pathname does not name a parent
   485      * directory.
   487      * directory.
   486      *
   488      *
   487      * <p> The <em>parent</em> of an abstract pathname consists of the
   489      * <p> The <em>parent</em> of an abstract pathname consists of the
   488      * pathname's prefix, if any, and each name in the pathname's name
   490      * pathname's prefix, if any, and each name in the pathname's name
   489      * sequence except for the last.  If the name sequence is empty then
   491      * sequence except for the last.  If the name sequence is empty then
   490      * the pathname does not name a parent directory.
   492      * the pathname does not name a parent directory.
   491      *
   493      *
   492      * @return  The abstract pathname of the parent directory named by this
   494      * @return  The abstract pathname of the parent directory named by this
   493      *          abstract pathname, or <code>null</code> if this pathname
   495      *          abstract pathname, or {@code null} if this pathname
   494      *          does not name a parent
   496      *          does not name a parent
   495      *
   497      *
   496      * @since 1.2
   498      * @since 1.2
   497      */
   499      */
   498     public File getParentFile() {
   500     public File getParentFile() {
   516     /* -- Path operations -- */
   518     /* -- Path operations -- */
   517 
   519 
   518     /**
   520     /**
   519      * Tests whether this abstract pathname is absolute.  The definition of
   521      * Tests whether this abstract pathname is absolute.  The definition of
   520      * absolute pathname is system dependent.  On UNIX systems, a pathname is
   522      * absolute pathname is system dependent.  On UNIX systems, a pathname is
   521      * absolute if its prefix is <code>"/"</code>.  On Microsoft Windows systems, a
   523      * absolute if its prefix is {@code "/"}.  On Microsoft Windows systems, a
   522      * pathname is absolute if its prefix is a drive specifier followed by
   524      * pathname is absolute if its prefix is a drive specifier followed by
   523      * <code>"\\"</code>, or if its prefix is <code>"\\\\"</code>.
   525      * {@code "\\"}, or if its prefix is {@code "\\\\"}.
   524      *
   526      *
   525      * @return  <code>true</code> if this abstract pathname is absolute,
   527      * @return  {@code true} if this abstract pathname is absolute,
   526      *          <code>false</code> otherwise
   528      *          {@code false} otherwise
   527      */
   529      */
   528     public boolean isAbsolute() {
   530     public boolean isAbsolute() {
   529         return fs.isAbsolute(this);
   531         return fs.isAbsolute(this);
   530     }
   532     }
   531 
   533 
   534      *
   536      *
   535      * <p> If this abstract pathname is already absolute, then the pathname
   537      * <p> If this abstract pathname is already absolute, then the pathname
   536      * string is simply returned as if by the {@link #getPath}
   538      * string is simply returned as if by the {@link #getPath}
   537      * method.  If this abstract pathname is the empty abstract pathname then
   539      * method.  If this abstract pathname is the empty abstract pathname then
   538      * the pathname string of the current user directory, which is named by the
   540      * the pathname string of the current user directory, which is named by the
   539      * system property <code>user.dir</code>, is returned.  Otherwise this
   541      * system property {@code user.dir}, is returned.  Otherwise this
   540      * pathname is resolved in a system-dependent way.  On UNIX systems, a
   542      * pathname is resolved in a system-dependent way.  On UNIX systems, a
   541      * relative pathname is made absolute by resolving it against the current
   543      * relative pathname is made absolute by resolving it against the current
   542      * user directory.  On Microsoft Windows systems, a relative pathname is made absolute
   544      * user directory.  On Microsoft Windows systems, a relative pathname is made absolute
   543      * by resolving it against the current directory of the drive named by the
   545      * by resolving it against the current directory of the drive named by the
   544      * pathname, if any; if not, it is resolved against the current user
   546      * pathname, if any; if not, it is resolved against the current user
   654             p = p + "/";
   656             p = p + "/";
   655         return p;
   657         return p;
   656     }
   658     }
   657 
   659 
   658     /**
   660     /**
   659      * Converts this abstract pathname into a <code>file:</code> URL.  The
   661      * Converts this abstract pathname into a {@code file:} URL.  The
   660      * exact form of the URL is system-dependent.  If it can be determined that
   662      * exact form of the URL is system-dependent.  If it can be determined that
   661      * the file denoted by this abstract pathname is a directory, then the
   663      * the file denoted by this abstract pathname is a directory, then the
   662      * resulting URL will end with a slash.
   664      * resulting URL will end with a slash.
   663      *
   665      *
   664      * @return  A URL object representing the equivalent file URL
   666      * @return  A URL object representing the equivalent file URL
   747      * abstract pathname. On some platforms it may be possible to start the
   749      * abstract pathname. On some platforms it may be possible to start the
   748      * Java virtual machine with special privileges that allow it to read
   750      * Java virtual machine with special privileges that allow it to read
   749      * files that are marked as unreadable. Consequently this method may return
   751      * files that are marked as unreadable. Consequently this method may return
   750      * {@code true} even though the file does not have read permissions.
   752      * {@code true} even though the file does not have read permissions.
   751      *
   753      *
   752      * @return  <code>true</code> if and only if the file specified by this
   754      * @return  {@code true} if and only if the file specified by this
   753      *          abstract pathname exists <em>and</em> can be read by the
   755      *          abstract pathname exists <em>and</em> can be read by the
   754      *          application; <code>false</code> otherwise
   756      *          application; {@code false} otherwise
   755      *
   757      *
   756      * @throws  SecurityException
   758      * @throws  SecurityException
   757      *          If a security manager exists and its {@link
   759      *          If a security manager exists and its {@link
   758      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   760      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   759      *          method denies read access to the file
   761      *          method denies read access to the file
   774      * abstract pathname. On some platforms it may be possible to start the
   776      * abstract pathname. On some platforms it may be possible to start the
   775      * Java virtual machine with special privileges that allow it to modify
   777      * Java virtual machine with special privileges that allow it to modify
   776      * files that are marked read-only. Consequently this method may return
   778      * files that are marked read-only. Consequently this method may return
   777      * {@code true} even though the file is marked read-only.
   779      * {@code true} even though the file is marked read-only.
   778      *
   780      *
   779      * @return  <code>true</code> if and only if the file system actually
   781      * @return  {@code true} if and only if the file system actually
   780      *          contains a file denoted by this abstract pathname <em>and</em>
   782      *          contains a file denoted by this abstract pathname <em>and</em>
   781      *          the application is allowed to write to the file;
   783      *          the application is allowed to write to the file;
   782      *          <code>false</code> otherwise.
   784      *          {@code false} otherwise.
   783      *
   785      *
   784      * @throws  SecurityException
   786      * @throws  SecurityException
   785      *          If a security manager exists and its {@link
   787      *          If a security manager exists and its {@link
   786      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
   788      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
   787      *          method denies write access to the file
   789      *          method denies write access to the file
   799 
   801 
   800     /**
   802     /**
   801      * Tests whether the file or directory denoted by this abstract pathname
   803      * Tests whether the file or directory denoted by this abstract pathname
   802      * exists.
   804      * exists.
   803      *
   805      *
   804      * @return  <code>true</code> if and only if the file or directory denoted
   806      * @return  {@code true} if and only if the file or directory denoted
   805      *          by this abstract pathname exists; <code>false</code> otherwise
   807      *          by this abstract pathname exists; {@code false} otherwise
   806      *
   808      *
   807      * @throws  SecurityException
   809      * @throws  SecurityException
   808      *          If a security manager exists and its {@link
   810      *          If a security manager exists and its {@link
   809      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   811      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   810      *          method denies read access to the file or directory
   812      *          method denies read access to the file or directory
   828      * that the file is not a directory, or where several attributes of the
   830      * that the file is not a directory, or where several attributes of the
   829      * same file are required at the same time, then the {@link
   831      * same file are required at the same time, then the {@link
   830      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   832      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   831      * Files.readAttributes} method may be used.
   833      * Files.readAttributes} method may be used.
   832      *
   834      *
   833      * @return <code>true</code> if and only if the file denoted by this
   835      * @return {@code true} if and only if the file denoted by this
   834      *          abstract pathname exists <em>and</em> is a directory;
   836      *          abstract pathname exists <em>and</em> is a directory;
   835      *          <code>false</code> otherwise
   837      *          {@code false} otherwise
   836      *
   838      *
   837      * @throws  SecurityException
   839      * @throws  SecurityException
   838      *          If a security manager exists and its {@link
   840      *          If a security manager exists and its {@link
   839      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   841      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   840      *          method denies read access to the file
   842      *          method denies read access to the file
   861      * that the file is not a normal file, or where several attributes of the
   863      * that the file is not a normal file, or where several attributes of the
   862      * same file are required at the same time, then the {@link
   864      * same file are required at the same time, then the {@link
   863      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   865      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   864      * Files.readAttributes} method may be used.
   866      * Files.readAttributes} method may be used.
   865      *
   867      *
   866      * @return  <code>true</code> if and only if the file denoted by this
   868      * @return  {@code true} if and only if the file denoted by this
   867      *          abstract pathname exists <em>and</em> is a normal file;
   869      *          abstract pathname exists <em>and</em> is a normal file;
   868      *          <code>false</code> otherwise
   870      *          {@code false} otherwise
   869      *
   871      *
   870      * @throws  SecurityException
   872      * @throws  SecurityException
   871      *          If a security manager exists and its {@link
   873      *          If a security manager exists and its {@link
   872      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   874      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   873      *          method denies read access to the file
   875      *          method denies read access to the file
   885 
   887 
   886     /**
   888     /**
   887      * Tests whether the file named by this abstract pathname is a hidden
   889      * Tests whether the file named by this abstract pathname is a hidden
   888      * file.  The exact definition of <em>hidden</em> is system-dependent.  On
   890      * file.  The exact definition of <em>hidden</em> is system-dependent.  On
   889      * UNIX systems, a file is considered to be hidden if its name begins with
   891      * UNIX systems, a file is considered to be hidden if its name begins with
   890      * a period character (<code>'.'</code>).  On Microsoft Windows systems, a file is
   892      * a period character ({@code '.'}).  On Microsoft Windows systems, a file is
   891      * considered to be hidden if it has been marked as such in the filesystem.
   893      * considered to be hidden if it has been marked as such in the filesystem.
   892      *
   894      *
   893      * @return  <code>true</code> if and only if the file denoted by this
   895      * @return  {@code true} if and only if the file denoted by this
   894      *          abstract pathname is hidden according to the conventions of the
   896      *          abstract pathname is hidden according to the conventions of the
   895      *          underlying platform
   897      *          underlying platform
   896      *
   898      *
   897      * @throws  SecurityException
   899      * @throws  SecurityException
   898      *          If a security manager exists and its {@link
   900      *          If a security manager exists and its {@link
   930      * Files.readAttributes} method may be used.  If however only the
   932      * Files.readAttributes} method may be used.  If however only the
   931      * time of last modification is required, then the
   933      * time of last modification is required, then the
   932      * {@link java.nio.file.Files#getLastModifiedTime(Path,LinkOption[])
   934      * {@link java.nio.file.Files#getLastModifiedTime(Path,LinkOption[])
   933      * Files.getLastModifiedTime} method may be used instead.
   935      * Files.getLastModifiedTime} method may be used instead.
   934      *
   936      *
   935      * @return  A <code>long</code> value representing the time the file was
   937      * @return  A {@code long} value representing the time the file was
   936      *          last modified, measured in milliseconds since the epoch
   938      *          last modified, measured in milliseconds since the epoch
   937      *          (00:00:00 GMT, January 1, 1970), or <code>0L</code> if the
   939      *          (00:00:00 GMT, January 1, 1970), or {@code 0L} if the
   938      *          file does not exist or if an I/O error occurs.  The value may
   940      *          file does not exist or if an I/O error occurs.  The value may
   939      *          be negative indicating the number of milliseconds before the
   941      *          be negative indicating the number of milliseconds before the
   940      *          epoch
   942      *          epoch
   941      *
   943      *
   942      * @throws  SecurityException
   944      * @throws  SecurityException
   964      * are required at the same time, then the {@link
   966      * are required at the same time, then the {@link
   965      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   967      * java.nio.file.Files#readAttributes(Path,Class,LinkOption[])
   966      * Files.readAttributes} method may be used.
   968      * Files.readAttributes} method may be used.
   967      *
   969      *
   968      * @return  The length, in bytes, of the file denoted by this abstract
   970      * @return  The length, in bytes, of the file denoted by this abstract
   969      *          pathname, or <code>0L</code> if the file does not exist.  Some
   971      *          pathname, or {@code 0L} if the file does not exist.  Some
   970      *          operating systems may return <code>0L</code> for pathnames
   972      *          operating systems may return {@code 0L} for pathnames
   971      *          denoting system-dependent entities such as devices or pipes.
   973      *          denoting system-dependent entities such as devices or pipes.
   972      *
   974      *
   973      * @throws  SecurityException
   975      * @throws  SecurityException
   974      *          If a security manager exists and its {@link
   976      *          If a security manager exists and its {@link
   975      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   977      *          java.lang.SecurityManager#checkRead(java.lang.String)}
   999      * Note: this method should <i>not</i> be used for file-locking, as
  1001      * Note: this method should <i>not</i> be used for file-locking, as
  1000      * the resulting protocol cannot be made to work reliably. The
  1002      * the resulting protocol cannot be made to work reliably. The
  1001      * {@link java.nio.channels.FileLock FileLock}
  1003      * {@link java.nio.channels.FileLock FileLock}
  1002      * facility should be used instead.
  1004      * facility should be used instead.
  1003      *
  1005      *
  1004      * @return  <code>true</code> if the named file does not exist and was
  1006      * @return  {@code true} if the named file does not exist and was
  1005      *          successfully created; <code>false</code> if the named file
  1007      *          successfully created; {@code false} if the named file
  1006      *          already exists
  1008      *          already exists
  1007      *
  1009      *
  1008      * @throws  IOException
  1010      * @throws  IOException
  1009      *          If an I/O error occurred
  1011      *          If an I/O error occurred
  1010      *
  1012      *
  1032      * <p> Note that the {@link java.nio.file.Files} class defines the {@link
  1034      * <p> Note that the {@link java.nio.file.Files} class defines the {@link
  1033      * java.nio.file.Files#delete(Path) delete} method to throw an {@link IOException}
  1035      * java.nio.file.Files#delete(Path) delete} method to throw an {@link IOException}
  1034      * when a file cannot be deleted. This is useful for error reporting and to
  1036      * when a file cannot be deleted. This is useful for error reporting and to
  1035      * diagnose why a file cannot be deleted.
  1037      * diagnose why a file cannot be deleted.
  1036      *
  1038      *
  1037      * @return  <code>true</code> if and only if the file or directory is
  1039      * @return  {@code true} if and only if the file or directory is
  1038      *          successfully deleted; <code>false</code> otherwise
  1040      *          successfully deleted; {@code false} otherwise
  1039      *
  1041      *
  1040      * @throws  SecurityException
  1042      * @throws  SecurityException
  1041      *          If a security manager exists and its {@link
  1043      *          If a security manager exists and its {@link
  1042      *          java.lang.SecurityManager#checkDelete} method denies
  1044      *          java.lang.SecurityManager#checkDelete} method denies
  1043      *          delete access to the file
  1045      *          delete access to the file
  1307     }
  1309     }
  1308 
  1310 
  1309     /**
  1311     /**
  1310      * Creates the directory named by this abstract pathname.
  1312      * Creates the directory named by this abstract pathname.
  1311      *
  1313      *
  1312      * @return  <code>true</code> if and only if the directory was
  1314      * @return  {@code true} if and only if the directory was
  1313      *          created; <code>false</code> otherwise
  1315      *          created; {@code false} otherwise
  1314      *
  1316      *
  1315      * @throws  SecurityException
  1317      * @throws  SecurityException
  1316      *          If a security manager exists and its {@link
  1318      *          If a security manager exists and its {@link
  1317      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1319      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1318      *          method does not permit the named directory to be created
  1320      *          method does not permit the named directory to be created
  1332      * Creates the directory named by this abstract pathname, including any
  1334      * Creates the directory named by this abstract pathname, including any
  1333      * necessary but nonexistent parent directories.  Note that if this
  1335      * necessary but nonexistent parent directories.  Note that if this
  1334      * operation fails it may have succeeded in creating some of the necessary
  1336      * operation fails it may have succeeded in creating some of the necessary
  1335      * parent directories.
  1337      * parent directories.
  1336      *
  1338      *
  1337      * @return  <code>true</code> if and only if the directory was created,
  1339      * @return  {@code true} if and only if the directory was created,
  1338      *          along with all necessary parent directories; <code>false</code>
  1340      *          along with all necessary parent directories; {@code false}
  1339      *          otherwise
  1341      *          otherwise
  1340      *
  1342      *
  1341      * @throws  SecurityException
  1343      * @throws  SecurityException
  1342      *          If a security manager exists and its {@link
  1344      *          If a security manager exists and its {@link
  1343      *          java.lang.SecurityManager#checkRead(java.lang.String)}
  1345      *          java.lang.SecurityManager#checkRead(java.lang.String)}
  1381      * java.nio.file.Files#move move} method to move or rename a file in a
  1383      * java.nio.file.Files#move move} method to move or rename a file in a
  1382      * platform independent manner.
  1384      * platform independent manner.
  1383      *
  1385      *
  1384      * @param  dest  The new abstract pathname for the named file
  1386      * @param  dest  The new abstract pathname for the named file
  1385      *
  1387      *
  1386      * @return  <code>true</code> if and only if the renaming succeeded;
  1388      * @return  {@code true} if and only if the renaming succeeded;
  1387      *          <code>false</code> otherwise
  1389      *          {@code false} otherwise
  1388      *
  1390      *
  1389      * @throws  SecurityException
  1391      * @throws  SecurityException
  1390      *          If a security manager exists and its {@link
  1392      *          If a security manager exists and its {@link
  1391      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1393      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1392      *          method denies write access to either the old or new pathnames
  1394      *          method denies write access to either the old or new pathnames
  1393      *
  1395      *
  1394      * @throws  NullPointerException
  1396      * @throws  NullPointerException
  1395      *          If parameter <code>dest</code> is <code>null</code>
  1397      *          If parameter {@code dest} is {@code null}
  1396      */
  1398      */
  1397     public boolean renameTo(File dest) {
  1399     public boolean renameTo(File dest) {
  1398         if (dest == null) {
  1400         if (dest == null) {
  1399             throw new NullPointerException();
  1401             throw new NullPointerException();
  1400         }
  1402         }
  1416      * <p> All platforms support file-modification times to the nearest second,
  1418      * <p> All platforms support file-modification times to the nearest second,
  1417      * but some provide more precision.  The argument will be truncated to fit
  1419      * but some provide more precision.  The argument will be truncated to fit
  1418      * the supported precision.  If the operation succeeds and no intervening
  1420      * the supported precision.  If the operation succeeds and no intervening
  1419      * operations on the file take place, then the next invocation of the
  1421      * operations on the file take place, then the next invocation of the
  1420      * {@link #lastModified} method will return the (possibly
  1422      * {@link #lastModified} method will return the (possibly
  1421      * truncated) <code>time</code> argument that was passed to this method.
  1423      * truncated) {@code time} argument that was passed to this method.
  1422      *
  1424      *
  1423      * @param  time  The new last-modified time, measured in milliseconds since
  1425      * @param  time  The new last-modified time, measured in milliseconds since
  1424      *               the epoch (00:00:00 GMT, January 1, 1970)
  1426      *               the epoch (00:00:00 GMT, January 1, 1970)
  1425      *
  1427      *
  1426      * @return <code>true</code> if and only if the operation succeeded;
  1428      * @return {@code true} if and only if the operation succeeded;
  1427      *          <code>false</code> otherwise
  1429      *          {@code false} otherwise
  1428      *
  1430      *
  1429      * @throws  IllegalArgumentException  If the argument is negative
  1431      * @throws  IllegalArgumentException  If the argument is negative
  1430      *
  1432      *
  1431      * @throws  SecurityException
  1433      * @throws  SecurityException
  1432      *          If a security manager exists and its {@link
  1434      *          If a security manager exists and its {@link
  1454      * to allow write access. On some platforms it may be possible to start the
  1456      * to allow write access. On some platforms it may be possible to start the
  1455      * Java virtual machine with special privileges that allow it to modify
  1457      * Java virtual machine with special privileges that allow it to modify
  1456      * files that are marked read-only. Whether or not a read-only file or
  1458      * files that are marked read-only. Whether or not a read-only file or
  1457      * directory may be deleted depends upon the underlying system.
  1459      * directory may be deleted depends upon the underlying system.
  1458      *
  1460      *
  1459      * @return <code>true</code> if and only if the operation succeeded;
  1461      * @return {@code true} if and only if the operation succeeded;
  1460      *          <code>false</code> otherwise
  1462      *          {@code false} otherwise
  1461      *
  1463      *
  1462      * @throws  SecurityException
  1464      * @throws  SecurityException
  1463      *          If a security manager exists and its {@link
  1465      *          If a security manager exists and its {@link
  1464      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1466      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  1465      *          method denies write access to the named file
  1467      *          method denies write access to the named file
  1486      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1488      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1487      * file attributes including file permissions. This may be used when finer
  1489      * file attributes including file permissions. This may be used when finer
  1488      * manipulation of file permissions is required.
  1490      * manipulation of file permissions is required.
  1489      *
  1491      *
  1490      * @param   writable
  1492      * @param   writable
  1491      *          If <code>true</code>, sets the access permission to allow write
  1493      *          If {@code true}, sets the access permission to allow write
  1492      *          operations; if <code>false</code> to disallow write operations
  1494      *          operations; if {@code false} to disallow write operations
  1493      *
  1495      *
  1494      * @param   ownerOnly
  1496      * @param   ownerOnly
  1495      *          If <code>true</code>, the write permission applies only to the
  1497      *          If {@code true}, the write permission applies only to the
  1496      *          owner's write permission; otherwise, it applies to everybody.  If
  1498      *          owner's write permission; otherwise, it applies to everybody.  If
  1497      *          the underlying file system can not distinguish the owner's write
  1499      *          the underlying file system can not distinguish the owner's write
  1498      *          permission from that of others, then the permission will apply to
  1500      *          permission from that of others, then the permission will apply to
  1499      *          everybody, regardless of this value.
  1501      *          everybody, regardless of this value.
  1500      *
  1502      *
  1501      * @return  <code>true</code> if and only if the operation succeeded. The
  1503      * @return  {@code true} if and only if the operation succeeded. The
  1502      *          operation will fail if the user does not have permission to change
  1504      *          operation will fail if the user does not have permission to change
  1503      *          the access permissions of this abstract pathname.
  1505      *          the access permissions of this abstract pathname.
  1504      *
  1506      *
  1505      * @throws  SecurityException
  1507      * @throws  SecurityException
  1506      *          If a security manager exists and its {@link
  1508      *          If a security manager exists and its {@link
  1532      * <pre>{@code
  1534      * <pre>{@code
  1533      *     file.setWritable(arg, true)
  1535      *     file.setWritable(arg, true)
  1534      * }</pre>
  1536      * }</pre>
  1535      *
  1537      *
  1536      * @param   writable
  1538      * @param   writable
  1537      *          If <code>true</code>, sets the access permission to allow write
  1539      *          If {@code true}, sets the access permission to allow write
  1538      *          operations; if <code>false</code> to disallow write operations
  1540      *          operations; if {@code false} to disallow write operations
  1539      *
  1541      *
  1540      * @return  <code>true</code> if and only if the operation succeeded.  The
  1542      * @return  {@code true} if and only if the operation succeeded.  The
  1541      *          operation will fail if the user does not have permission to
  1543      *          operation will fail if the user does not have permission to
  1542      *          change the access permissions of this abstract pathname.
  1544      *          change the access permissions of this abstract pathname.
  1543      *
  1545      *
  1544      * @throws  SecurityException
  1546      * @throws  SecurityException
  1545      *          If a security manager exists and its {@link
  1547      *          If a security manager exists and its {@link
  1561      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1563      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1562      * file attributes including file permissions. This may be used when finer
  1564      * file attributes including file permissions. This may be used when finer
  1563      * manipulation of file permissions is required.
  1565      * manipulation of file permissions is required.
  1564      *
  1566      *
  1565      * @param   readable
  1567      * @param   readable
  1566      *          If <code>true</code>, sets the access permission to allow read
  1568      *          If {@code true}, sets the access permission to allow read
  1567      *          operations; if <code>false</code> to disallow read operations
  1569      *          operations; if {@code false} to disallow read operations
  1568      *
  1570      *
  1569      * @param   ownerOnly
  1571      * @param   ownerOnly
  1570      *          If <code>true</code>, the read permission applies only to the
  1572      *          If {@code true}, the read permission applies only to the
  1571      *          owner's read permission; otherwise, it applies to everybody.  If
  1573      *          owner's read permission; otherwise, it applies to everybody.  If
  1572      *          the underlying file system can not distinguish the owner's read
  1574      *          the underlying file system can not distinguish the owner's read
  1573      *          permission from that of others, then the permission will apply to
  1575      *          permission from that of others, then the permission will apply to
  1574      *          everybody, regardless of this value.
  1576      *          everybody, regardless of this value.
  1575      *
  1577      *
  1576      * @return  <code>true</code> if and only if the operation succeeded.  The
  1578      * @return  {@code true} if and only if the operation succeeded.  The
  1577      *          operation will fail if the user does not have permission to
  1579      *          operation will fail if the user does not have permission to
  1578      *          change the access permissions of this abstract pathname.  If
  1580      *          change the access permissions of this abstract pathname.  If
  1579      *          <code>readable</code> is <code>false</code> and the underlying
  1581      *          {@code readable} is {@code false} and the underlying
  1580      *          file system does not implement a read permission, then the
  1582      *          file system does not implement a read permission, then the
  1581      *          operation will fail.
  1583      *          operation will fail.
  1582      *
  1584      *
  1583      * @throws  SecurityException
  1585      * @throws  SecurityException
  1584      *          If a security manager exists and its {@link
  1586      *          If a security manager exists and its {@link
  1610      * <pre>{@code
  1612      * <pre>{@code
  1611      *     file.setReadable(arg, true)
  1613      *     file.setReadable(arg, true)
  1612      * }</pre>
  1614      * }</pre>
  1613      *
  1615      *
  1614      * @param  readable
  1616      * @param  readable
  1615      *          If <code>true</code>, sets the access permission to allow read
  1617      *          If {@code true}, sets the access permission to allow read
  1616      *          operations; if <code>false</code> to disallow read operations
  1618      *          operations; if {@code false} to disallow read operations
  1617      *
  1619      *
  1618      * @return  <code>true</code> if and only if the operation succeeded.  The
  1620      * @return  {@code true} if and only if the operation succeeded.  The
  1619      *          operation will fail if the user does not have permission to
  1621      *          operation will fail if the user does not have permission to
  1620      *          change the access permissions of this abstract pathname.  If
  1622      *          change the access permissions of this abstract pathname.  If
  1621      *          <code>readable</code> is <code>false</code> and the underlying
  1623      *          {@code readable} is {@code false} and the underlying
  1622      *          file system does not implement a read permission, then the
  1624      *          file system does not implement a read permission, then the
  1623      *          operation will fail.
  1625      *          operation will fail.
  1624      *
  1626      *
  1625      * @throws  SecurityException
  1627      * @throws  SecurityException
  1626      *          If a security manager exists and its {@link
  1628      *          If a security manager exists and its {@link
  1642      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1644      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1643      * file attributes including file permissions. This may be used when finer
  1645      * file attributes including file permissions. This may be used when finer
  1644      * manipulation of file permissions is required.
  1646      * manipulation of file permissions is required.
  1645      *
  1647      *
  1646      * @param   executable
  1648      * @param   executable
  1647      *          If <code>true</code>, sets the access permission to allow execute
  1649      *          If {@code true}, sets the access permission to allow execute
  1648      *          operations; if <code>false</code> to disallow execute operations
  1650      *          operations; if {@code false} to disallow execute operations
  1649      *
  1651      *
  1650      * @param   ownerOnly
  1652      * @param   ownerOnly
  1651      *          If <code>true</code>, the execute permission applies only to the
  1653      *          If {@code true}, the execute permission applies only to the
  1652      *          owner's execute permission; otherwise, it applies to everybody.
  1654      *          owner's execute permission; otherwise, it applies to everybody.
  1653      *          If the underlying file system can not distinguish the owner's
  1655      *          If the underlying file system can not distinguish the owner's
  1654      *          execute permission from that of others, then the permission will
  1656      *          execute permission from that of others, then the permission will
  1655      *          apply to everybody, regardless of this value.
  1657      *          apply to everybody, regardless of this value.
  1656      *
  1658      *
  1657      * @return  <code>true</code> if and only if the operation succeeded.  The
  1659      * @return  {@code true} if and only if the operation succeeded.  The
  1658      *          operation will fail if the user does not have permission to
  1660      *          operation will fail if the user does not have permission to
  1659      *          change the access permissions of this abstract pathname.  If
  1661      *          change the access permissions of this abstract pathname.  If
  1660      *          <code>executable</code> is <code>false</code> and the underlying
  1662      *          {@code executable} is {@code false} and the underlying
  1661      *          file system does not implement an execute permission, then the
  1663      *          file system does not implement an execute permission, then the
  1662      *          operation will fail.
  1664      *          operation will fail.
  1663      *
  1665      *
  1664      * @throws  SecurityException
  1666      * @throws  SecurityException
  1665      *          If a security manager exists and its {@link
  1667      *          If a security manager exists and its {@link
  1691      * <pre>{@code
  1693      * <pre>{@code
  1692      *     file.setExecutable(arg, true)
  1694      *     file.setExecutable(arg, true)
  1693      * }</pre>
  1695      * }</pre>
  1694      *
  1696      *
  1695      * @param   executable
  1697      * @param   executable
  1696      *          If <code>true</code>, sets the access permission to allow execute
  1698      *          If {@code true}, sets the access permission to allow execute
  1697      *          operations; if <code>false</code> to disallow execute operations
  1699      *          operations; if {@code false} to disallow execute operations
  1698      *
  1700      *
  1699      * @return   <code>true</code> if and only if the operation succeeded.  The
  1701      * @return   {@code true} if and only if the operation succeeded.  The
  1700      *           operation will fail if the user does not have permission to
  1702      *           operation will fail if the user does not have permission to
  1701      *           change the access permissions of this abstract pathname.  If
  1703      *           change the access permissions of this abstract pathname.  If
  1702      *           <code>executable</code> is <code>false</code> and the underlying
  1704      *           {@code executable} is {@code false} and the underlying
  1703      *           file system does not implement an execute permission, then the
  1705      *           file system does not implement an execute permission, then the
  1704      *           operation will fail.
  1706      *           operation will fail.
  1705      *
  1707      *
  1706      * @throws  SecurityException
  1708      * @throws  SecurityException
  1707      *          If a security manager exists and its {@link
  1709      *          If a security manager exists and its {@link
  1719      * abstract pathname. On some platforms it may be possible to start the
  1721      * abstract pathname. On some platforms it may be possible to start the
  1720      * Java virtual machine with special privileges that allow it to execute
  1722      * Java virtual machine with special privileges that allow it to execute
  1721      * files that are not marked executable. Consequently this method may return
  1723      * files that are not marked executable. Consequently this method may return
  1722      * {@code true} even though the file does not have execute permissions.
  1724      * {@code true} even though the file does not have execute permissions.
  1723      *
  1725      *
  1724      * @return  <code>true</code> if and only if the abstract pathname exists
  1726      * @return  {@code true} if and only if the abstract pathname exists
  1725      *          <em>and</em> the application is allowed to execute the file
  1727      *          <em>and</em> the application is allowed to execute the file
  1726      *
  1728      *
  1727      * @throws  SecurityException
  1729      * @throws  SecurityException
  1728      *          If a security manager exists and its {@link
  1730      *          If a security manager exists and its {@link
  1729      *          java.lang.SecurityManager#checkExec(java.lang.String)}
  1731      *          java.lang.SecurityManager#checkExec(java.lang.String)}
  2003      *
  2005      *
  2004      * This method provides only part of a temporary-file facility.  To arrange
  2006      * This method provides only part of a temporary-file facility.  To arrange
  2005      * for a file created by this method to be deleted automatically, use the
  2007      * for a file created by this method to be deleted automatically, use the
  2006      * {@link #deleteOnExit} method.
  2008      * {@link #deleteOnExit} method.
  2007      *
  2009      *
  2008      * <p> The <code>prefix</code> argument must be at least three characters
  2010      * <p> The {@code prefix} argument must be at least three characters
  2009      * long.  It is recommended that the prefix be a short, meaningful string
  2011      * long.  It is recommended that the prefix be a short, meaningful string
  2010      * such as <code>"hjb"</code> or <code>"mail"</code>.  The
  2012      * such as {@code "hjb"} or {@code "mail"}.  The
  2011      * <code>suffix</code> argument may be <code>null</code>, in which case the
  2013      * {@code suffix} argument may be {@code null}, in which case the
  2012      * suffix <code>".tmp"</code> will be used.
  2014      * suffix {@code ".tmp"} will be used.
  2013      *
  2015      *
  2014      * <p> To create the new file, the prefix and the suffix may first be
  2016      * <p> To create the new file, the prefix and the suffix may first be
  2015      * adjusted to fit the limitations of the underlying platform.  If the
  2017      * adjusted to fit the limitations of the underlying platform.  If the
  2016      * prefix is too long then it will be truncated, but its first three
  2018      * prefix is too long then it will be truncated, but its first three
  2017      * characters will always be preserved.  If the suffix is too long then it
  2019      * characters will always be preserved.  If the suffix is too long then it
  2018      * too will be truncated, but if it begins with a period character
  2020      * too will be truncated, but if it begins with a period character
  2019      * (<code>'.'</code>) then the period and the first three characters
  2021      * ({@code '.'}) then the period and the first three characters
  2020      * following it will always be preserved.  Once these adjustments have been
  2022      * following it will always be preserved.  Once these adjustments have been
  2021      * made the name of the new file will be generated by concatenating the
  2023      * made the name of the new file will be generated by concatenating the
  2022      * prefix, five or more internally-generated characters, and the suffix.
  2024      * prefix, five or more internally-generated characters, and the suffix.
  2023      *
  2025      *
  2024      * <p> If the <code>directory</code> argument is <code>null</code> then the
  2026      * <p> If the {@code directory} argument is {@code null} then the
  2025      * system-dependent default temporary-file directory will be used.  The
  2027      * system-dependent default temporary-file directory will be used.  The
  2026      * default temporary-file directory is specified by the system property
  2028      * default temporary-file directory is specified by the system property
  2027      * <code>java.io.tmpdir</code>.  On UNIX systems the default value of this
  2029      * {@code java.io.tmpdir}.  On UNIX systems the default value of this
  2028      * property is typically <code>"/tmp"</code> or <code>"/var/tmp"</code>; on
  2030      * property is typically {@code "/tmp"} or {@code "/var/tmp"}; on
  2029      * Microsoft Windows systems it is typically <code>"C:\\WINNT\\TEMP"</code>.  A different
  2031      * Microsoft Windows systems it is typically {@code "C:\\WINNT\\TEMP"}.  A different
  2030      * value may be given to this system property when the Java virtual machine
  2032      * value may be given to this system property when the Java virtual machine
  2031      * is invoked, but programmatic changes to this property are not guaranteed
  2033      * is invoked, but programmatic changes to this property are not guaranteed
  2032      * to have any effect upon the temporary directory used by this method.
  2034      * to have any effect upon the temporary directory used by this method.
  2033      *
  2035      *
  2034      * @param  prefix     The prefix string to be used in generating the file's
  2036      * @param  prefix     The prefix string to be used in generating the file's
  2035      *                    name; must be at least three characters long
  2037      *                    name; must be at least three characters long
  2036      *
  2038      *
  2037      * @param  suffix     The suffix string to be used in generating the file's
  2039      * @param  suffix     The suffix string to be used in generating the file's
  2038      *                    name; may be <code>null</code>, in which case the
  2040      *                    name; may be {@code null}, in which case the
  2039      *                    suffix <code>".tmp"</code> will be used
  2041      *                    suffix {@code ".tmp"} will be used
  2040      *
  2042      *
  2041      * @param  directory  The directory in which the file is to be created, or
  2043      * @param  directory  The directory in which the file is to be created, or
  2042      *                    <code>null</code> if the default temporary-file
  2044      *                    {@code null} if the default temporary-file
  2043      *                    directory is to be used
  2045      *                    directory is to be used
  2044      *
  2046      *
  2045      * @return  An abstract pathname denoting a newly-created empty file
  2047      * @return  An abstract pathname denoting a newly-created empty file
  2046      *
  2048      *
  2047      * @throws  IllegalArgumentException
  2049      * @throws  IllegalArgumentException
  2048      *          If the <code>prefix</code> argument contains fewer than three
  2050      *          If the {@code prefix} argument contains fewer than three
  2049      *          characters
  2051      *          characters
  2050      *
  2052      *
  2051      * @throws  IOException  If a file could not be created
  2053      * @throws  IOException  If a file could not be created
  2052      *
  2054      *
  2053      * @throws  SecurityException
  2055      * @throws  SecurityException
  2109      *
  2111      *
  2110      * @param  prefix     The prefix string to be used in generating the file's
  2112      * @param  prefix     The prefix string to be used in generating the file's
  2111      *                    name; must be at least three characters long
  2113      *                    name; must be at least three characters long
  2112      *
  2114      *
  2113      * @param  suffix     The suffix string to be used in generating the file's
  2115      * @param  suffix     The suffix string to be used in generating the file's
  2114      *                    name; may be <code>null</code>, in which case the
  2116      *                    name; may be {@code null}, in which case the
  2115      *                    suffix <code>".tmp"</code> will be used
  2117      *                    suffix {@code ".tmp"} will be used
  2116      *
  2118      *
  2117      * @return  An abstract pathname denoting a newly-created empty file
  2119      * @return  An abstract pathname denoting a newly-created empty file
  2118      *
  2120      *
  2119      * @throws  IllegalArgumentException
  2121      * @throws  IllegalArgumentException
  2120      *          If the <code>prefix</code> argument contains fewer than three
  2122      *          If the {@code prefix} argument contains fewer than three
  2121      *          characters
  2123      *          characters
  2122      *
  2124      *
  2123      * @throws  IOException  If a file could not be created
  2125      * @throws  IOException  If a file could not be created
  2124      *
  2126      *
  2125      * @throws  SecurityException
  2127      * @throws  SecurityException
  2159         return fs.compare(this, pathname);
  2161         return fs.compare(this, pathname);
  2160     }
  2162     }
  2161 
  2163 
  2162     /**
  2164     /**
  2163      * Tests this abstract pathname for equality with the given object.
  2165      * Tests this abstract pathname for equality with the given object.
  2164      * Returns <code>true</code> if and only if the argument is not
  2166      * Returns {@code true} if and only if the argument is not
  2165      * <code>null</code> and is an abstract pathname that denotes the same file
  2167      * {@code null} and is an abstract pathname that denotes the same file
  2166      * or directory as this abstract pathname.  Whether or not two abstract
  2168      * or directory as this abstract pathname.  Whether or not two abstract
  2167      * pathnames are equal depends upon the underlying system.  On UNIX
  2169      * pathnames are equal depends upon the underlying system.  On UNIX
  2168      * systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
  2170      * systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
  2169      * systems it is not.
  2171      * systems it is not.
  2170      *
  2172      *
  2171      * @param   obj   The object to be compared with this abstract pathname
  2173      * @param   obj   The object to be compared with this abstract pathname
  2172      *
  2174      *
  2173      * @return  <code>true</code> if and only if the objects are the same;
  2175      * @return  {@code true} if and only if the objects are the same;
  2174      *          <code>false</code> otherwise
  2176      *          {@code false} otherwise
  2175      */
  2177      */
  2176     public boolean equals(Object obj) {
  2178     public boolean equals(Object obj) {
  2177         if ((obj != null) && (obj instanceof File)) {
  2179         if ((obj != null) && (obj instanceof File)) {
  2178             return compareTo((File)obj) == 0;
  2180             return compareTo((File)obj) == 0;
  2179         }
  2181         }
  2184      * Computes a hash code for this abstract pathname.  Because equality of
  2186      * Computes a hash code for this abstract pathname.  Because equality of
  2185      * abstract pathnames is inherently system-dependent, so is the computation
  2187      * abstract pathnames is inherently system-dependent, so is the computation
  2186      * of their hash codes.  On UNIX systems, the hash code of an abstract
  2188      * of their hash codes.  On UNIX systems, the hash code of an abstract
  2187      * pathname is equal to the exclusive <em>or</em> of the hash code
  2189      * pathname is equal to the exclusive <em>or</em> of the hash code
  2188      * of its pathname string and the decimal value
  2190      * of its pathname string and the decimal value
  2189      * <code>1234321</code>.  On Microsoft Windows systems, the hash
  2191      * {@code 1234321}.  On Microsoft Windows systems, the hash
  2190      * code is equal to the exclusive <em>or</em> of the hash code of
  2192      * code is equal to the exclusive <em>or</em> of the hash code of
  2191      * its pathname string converted to lower case and the decimal
  2193      * its pathname string converted to lower case and the decimal
  2192      * value <code>1234321</code>.  Locale is not taken into account on
  2194      * value {@code 1234321}.  Locale is not taken into account on
  2193      * lowercasing the pathname string.
  2195      * lowercasing the pathname string.
  2194      *
  2196      *
  2195      * @return  A hash code for this abstract pathname
  2197      * @return  A hash code for this abstract pathname
  2196      */
  2198      */
  2197     public int hashCode() {
  2199     public int hashCode() {
  2213      * The separator character is saved also so it can be replaced
  2215      * The separator character is saved also so it can be replaced
  2214      * in case the path is reconstituted on a different host type.
  2216      * in case the path is reconstituted on a different host type.
  2215      *
  2217      *
  2216      * @serialData  Default fields followed by separator character.
  2218      * @serialData  Default fields followed by separator character.
  2217      */
  2219      */
       
  2220     @java.io.Serial
  2218     private synchronized void writeObject(java.io.ObjectOutputStream s)
  2221     private synchronized void writeObject(java.io.ObjectOutputStream s)
  2219         throws IOException
  2222         throws IOException
  2220     {
  2223     {
  2221         s.defaultWriteObject();
  2224         s.defaultWriteObject();
  2222         s.writeChar(separatorChar); // Add the separator character
  2225         s.writeChar(separatorChar); // Add the separator character
  2226      * readObject is called to restore this filename.
  2229      * readObject is called to restore this filename.
  2227      * The original separator character is read.  If it is different
  2230      * The original separator character is read.  If it is different
  2228      * than the separator character on this system, then the old separator
  2231      * than the separator character on this system, then the old separator
  2229      * is replaced by the local separator.
  2232      * is replaced by the local separator.
  2230      */
  2233      */
       
  2234     @java.io.Serial
  2231     private synchronized void readObject(java.io.ObjectInputStream s)
  2235     private synchronized void readObject(java.io.ObjectInputStream s)
  2232          throws IOException, ClassNotFoundException
  2236          throws IOException, ClassNotFoundException
  2233     {
  2237     {
  2234         ObjectInputStream.GetField fields = s.readFields();
  2238         ObjectInputStream.GetField fields = s.readFields();
  2235         String pathField = (String)fields.get("path", null);
  2239         String pathField = (String)fields.get("path", null);
  2247             = UNSAFE.objectFieldOffset(File.class, "path");
  2251             = UNSAFE.objectFieldOffset(File.class, "path");
  2248     private static final long PREFIX_LENGTH_OFFSET
  2252     private static final long PREFIX_LENGTH_OFFSET
  2249             = UNSAFE.objectFieldOffset(File.class, "prefixLength");
  2253             = UNSAFE.objectFieldOffset(File.class, "prefixLength");
  2250 
  2254 
  2251     /** use serialVersionUID from JDK 1.0.2 for interoperability */
  2255     /** use serialVersionUID from JDK 1.0.2 for interoperability */
       
  2256     @java.io.Serial
  2252     private static final long serialVersionUID = 301077366599181567L;
  2257     private static final long serialVersionUID = 301077366599181567L;
  2253 
  2258 
  2254     // -- Integration with java.nio.file --
  2259     // -- Integration with java.nio.file --
  2255 
  2260 
  2256     private transient volatile Path filePath;
  2261     private transient volatile Path filePath;