📄 javaio.doc22.html
字号:
directory is returned; otherwise, <code>null</code> is returned.
<p><a name="29792"></a>
<p><font size=+1><strong>22.24.15 </strong> <code>public boolean <code><b>isAbsolute</b></code>()</code></font>
<p>
<a name="29793"></a>
The result is <code>true</code> if and only if the path represented by the File object is in absolute
form, indicating a complete name that starts from the root of the directory
hierarchy, rather than a name relative to some implied directory.
<p><a name="29795"></a>
<p><font size=+1><strong>22.24.16 </strong> <code>public boolean <code><b>exists</b></code>() throws SecurityException</code></font>
<p>
<a name="29799"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="29800"></a>
The result is <code>true</code> if and only if the file system actually contains a file that is specified by the path of the <code>File</code> object.<p>
<a name="29802"></a>
<p><font size=+1><strong>22.24.17 </strong> <code>public boolean <code><b>canRead</b></code>() throws SecurityException</code></font>
<p>
<a name="29806"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="29807"></a>
The result is <code>true</code> if and only if both of the following are true:<p>
<ul><a name="31770"></a>
<li>The file system actually contains a file specified by the path of the <code>File</code> object.
<a name="31771"></a>
<li>The file so specified can be read.
</ul><a name="29809"></a>
<p><font size=+1><strong>22.24.18 </strong> <code>public boolean <code><b>canWrite</b></code>() throws SecurityException</code></font>
<p>
<a name="29813"></a>
First, if there is a security manager, its <code>checkWrite</code> method <a href="javalang.doc16.html#14117">(§20.17.21)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="31776"></a>
The result is <code>true</code> if and only if both of the following are true:<p>
<ul><a name="31777"></a>
<li>The file system actually contains a file specified by the path of the <code>File</code> object.
<a name="31778"></a>
<li>The file so specified can be written.
</ul><a name="29816"></a>
<p><font size=+1><strong>22.24.19 </strong> <code>public boolean <code><b>isFile</b></code>() throws SecurityException</code></font>
<p>
<a name="29820"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="31784"></a>
The result is <code>true</code> if and only if both of the following are true:<p>
<ul><a name="31785"></a>
<li>The file system actually contains a file specified by the path of the <code>File</code> object.
<a name="31786"></a>
<li>The file so specified is a data file rather than a directory.
</ul><a name="29823"></a>
<p><font size=+1><strong>22.24.20 </strong> <code>public boolean <code><b>isDirectory</b></code>() throws SecurityException</code></font>
<p>
<a name="29827"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="31792"></a>
The result is <code>true</code> if and only if both of the following are true:<p>
<ul><a name="31793"></a>
<li>The file system actually contains a file specified by the path of the <code>File</code> object.
<a name="31794"></a>
<li>The file so specified is a directory rather than a data file.
</ul><a name="33515"></a>
<p>
<a name="29830"></a>
<p><font size=+1><strong>22.24.21 </strong> <code>public long <code><b>lastModified</b></code>() throws SecurityException</code></font>
<p>
<a name="29834"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="29835"></a>
An abstract modification time is returned. If two values returned by this method are compared, whether for the same file or for two different files, the smaller value represents an earlier modification time. Abstract modification times do not necessarily bear any relationship, even monotonicity, to times returned by the method <code>System.currentTimeMillis</code> <a href="javalang.doc17.html#5984">(§20.18.6)</a>.<p>
<a name="29840"></a>
<p><font size=+1><strong>22.24.22 </strong> <code>public long <code><b>length</b></code>() throws SecurityException</code></font>
<p>
<a name="29844"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="29845"></a>
The length of the file, measured in bytes, is returned.<p>
<a name="29847"></a>
<p><font size=+1><strong>22.24.23 </strong> <code>public boolean <code><b>mkdir</b></code>() throws SecurityException</code></font>
<p>
<a name="29851"></a>
First, if there is a security manager, its <code>checkWrite</code> method <a href="javalang.doc16.html#14117">(§20.17.21)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="29852"></a>
An attempt is made to create the directory specified by the path represented by this <code>File</code> object; the result is true if and only if the creation operation succeeds.<p>
<a name="29854"></a>
<p><font size=+1><strong>22.24.24 </strong> <code>public boolean <code><b>mkdirs</b></code>() throws SecurityException</code></font>
<p>
<a name="29858"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="30558"></a>
If the directory name represented by this <code>File</code> object has a parent directory name <a href="javaio.doc22.html#29790">(§22.24.14)</a>, an attempt is first made to create the parent directory; if this attempt fails, the result is <code>false</code>. Otherwise, once the parent directory has been determined to exist, or if the path has no parent, an attempt is made to create the directory specified by this <code>File</code> object. The result is <code>true</code> if and only if the creation operation succeeds.<p>
<a name="29861"></a>
<p><font size=+1><strong>22.24.25 </strong> <code>public String[] <code><b>list</b></code>() throws SecurityException</code></font>
<p>
<a name="29865"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="30575"></a>
If the path represented by this <code>File</code> object does not correspond to a directory in the file system, then <code>null</code> is returned. Otherwise, an array of strings is returned, one for each file in the directory (on UNIX systems, the names "<code>.</code>" and "<code>..</code>" are not included). Each string is a file name, not a complete path. There is no guarantee that the strings will appear in any particular order within the array; for example, they are not guaranteed to appear in alphabetical order.<p>
<a name="29868"></a>
<p><font size=+1><strong>22.24.26 </strong> <code>public String[] <code><b>list</b></code>(FilenameFilter filter)<br>throws SecurityException</code></font>
<p>
<a name="29872"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(§20.17.19)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="30594"></a>
If the path represented by this <code>File</code> object does not correspond to a directory in the file system, then <code>null</code> is returned. Otherwise, an array of strings is returned, one for each file in the directory (on UNIX systems, the names "<code>.</code>" and "<code>..</code>" are not included) whose name satisfies the given <code>filter</code>. Each string is a file name, not a complete path. There is no guarantee that the strings will appear in any particular order within the array; for example, they are not guaranteed to appear in alphabetical order. A file name satisfies the filter if and only if the value <code>true</code> results when the <code>accept</code> method <a href="javaio.doc22.html#30155">(§22.25.1)</a> of the filter is called with this <code>File</code> object and the name as arguments.<p>
<a name="29875"></a>
<p><font size=+1><strong>22.24.27 </strong> <code>public boolean <code><b>renameTo</b></code>(File dest)<br>throws SecurityException</code></font>
<p>
<a name="29879"></a>
First, if there is a security manager, its <code>checkWrite</code> method <a href="javalang.doc16.html#14117">(§20.17.21)</a> is called
twice, first with the path represented by this <code>File</code> object as its argument and again
with the path of <code>dest</code> as its argument.
<p><a name="30622"></a>
An attempt is made to rename the file specified by the path represented by this <code>File</code> object to the name specified by <code>dest</code>; the result is <code>true</code> if and only if the renaming operation succeeds.<p>
<a name="29882"></a>
<p><font size=+1><strong>22.24.28 </strong> <code>public boolean <code><b>delete</b></code>() throws SecurityException</code></font>
<p>
<a name="29886"></a>
First, if there is a security manager, its <code>checkDelete</code> method <a href="javalang.doc16.html#14118">(§20.17.22)</a> is called
with the path represented by this <code>File</code> object as its argument.
<p><a name="30604"></a>
An attempt is made to delete the file specified by the path represented by this <code>File</code> object; the result is <code>true</code> if and only if the deletion operation succeeds.<p>
<a name="30147"></a>
<h1>22.25 The Interface <code>java.io.FilenameFilter</code></h1>
<a name="30151"></a>
The <code>list</code> method <a href="javaio.doc22.html#29868">(§22.24.26)</a> of class <code>File</code> requires, as an argument, an object
that implements the <code>FilenameFilter</code> interface. The only purpose of such an
object is to provide a method <code>accept</code> that decides which files should appear in the
generated directory listing.
<p><pre><a name="30152"></a>public interface <code><b>FilenameFilter</b></code> {
<a name="30153"></a> public boolean <code><b>accept</b></code>(File dir, String name);
<a name="30154"></a>}
</pre><a name="30155"></a>
<p><font size=+1><strong>22.25.1 </strong> <code>public boolean <code><b>accept</b></code>(File dir, String name)</code></font>
<p>
<a name="30156"></a>
This method should return <code>true</code> if and only if the given file named <code>name</code> in the
directory <code>dir</code> is to appear in the final list of files generated by the <code>list</code> method
<a href="javaio.doc22.html#29868">(§22.24.26)</a> of class <code>File</code>.
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javaio.doc21.html">Prev</a> | <a href="javaio.doc23.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -