⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaio.doc22.html

📁 java语言规范
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html>
<head>
<title>The Java Language Specification The Package java.io </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
 
<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>
<hr><br>
 
<a name="29705"></a>
<center><h1>22.24  The Class  <code>java.io.File</code></h1></center>
<a name="29706"></a>
A <code>File</code> object contains a <i>path</i>, which is a character string that can be used to identify
a file within a file system. A path is assumed to consist of two parts, the <i>directory
</i> and the <i>file name</i>, separated by the last occurrence within the path of a 
particular character known as the <i>separator character</i>. Some methods provide 
access to parts of the path string; other methods operate on the file that is identified
by the path string. The details of such operations on files are to some extent 
dependent on the implementation of the host file system. The <code>File</code> class is 
designed to provide a set of abstract operations that are reasonably portable across 
otherwise incompatible file systems.
<p><pre><a name="29707"></a>public class <code><b>File</b></code> {
<a name="29708"></a>	public static final String <code><b>separator</b></code> =
<a name="29709"></a>		System.getProperty("file.separator");
<a name="29710"></a>	public static final char <code><b>separatorChar</b></code> =
<a name="29711"></a>		separator.charAt(0);
<a name="29712"></a>	public static final String <code><b>pathSeparator</b></code> =
<a name="29713"></a>		System.getProperty("path.separator");
<a name="33484"></a>	public static final char <code><b>pathSeparatorChar</b></code> =
<a name="33485"></a>		pathSeparator.charAt(0);
<a name="33486"></a>	public <code><b>File</b></code>(String path) throws NullPointerException;
<a name="29717"></a>	public <code><b>File</b></code>(String dirname, String name)
<a name="32555"></a>		throws NullPointerException
<a name="29718"></a>	public <code><b>File</b></code>(File dir, String name)
<a name="32556"></a>		throws NullPointerException
<a name="29719"></a>	public String <code><b>toString</b></code>();
<a name="29720"></a>	public boolean <code><b>equals</b></code>(Object obj);
<a name="29721"></a>	public int <code><b>hashCode</b></code>();
<a name="29722"></a>	public String <code><b>getName</b></code>();
<a name="29723"></a>	public String <code><b>getPath</b></code>();
<a name="29724"></a>	public String <code><b>getAbsolutePath</b></code>();
<a name="29725"></a>	public String <code><b>getParent</b></code>();
<a name="29726"></a>	public native boolean <code><b>isAbsolute</b></code>();
<a name="29727"></a>	public boolean <code><b>exists</b></code>() throws SecurityException;
<a name="29728"></a>	public boolean <code><b>canRead</b></code>() throws SecurityException;
<a name="29729"></a>	public boolean <code><b>canWrite</b></code>() throws SecurityException;
<a name="29730"></a>	public boolean <code><b>isFile</b></code>() throws SecurityException;
<a name="29731"></a>	public boolean <code><b>isDirectory</b></code>() throws SecurityException;
<a name="29732"></a>	public long <code><b>lastModified</b></code>() throws SecurityException;
<a name="29733"></a>	public long <code><b>length</b></code>() throws SecurityException;
<a name="29734"></a>	public boolean <code><b>mkdir</b></code>() throws SecurityException;
<a name="29735"></a>	public boolean <code><b>mkdirs</b></code>() throws SecurityException;
<a name="29736"></a>	public String[] <code><b>list</b></code>() throws SecurityException;
<a name="29737"></a>	public String[] <code><b>list</b></code>(FilenameFilter filter)
<a name="30850"></a>		throws SecurityException;
<a name="46182"></a>	public boolean <code><b>renameTo</b></code>(File dest) throws SecurityException;
<a name="29738"></a>	public boolean <code><b>delete</b></code>() throws SecurityException;
<a name="29740"></a>}
</pre><a name="29741"></a>
<p><font size=+1><strong>22.24.1   </strong> <code>public static final String <code><b>separator</b></code> = System.getProperty("file.separator");</code></font>
<p>
<a name="29742"></a>
This string should consist of a single character, whose value is also available in 
the field <code>separatorChar</code>; the string is provided merely for convenience.
<p><a name="29744"></a>
<p><font size=+1><strong>22.24.2   </strong> <code>public static final char <code><b>separatorChar</b></code> = separator.charAt(0);</code></font>
<p>
<a name="29745"></a>
The last occurrence of this character in a path string is assumed to separate the 
directory part of the path from the file name part of the path. On UNIX systems 
this character is typically <code>'/'</code>.
<p><a name="29746"></a>
<p><font size=+1><strong>22.24.3   </strong> <code>public static final String <code><b>pathSeparator</b></code> = System.getProperty("path.separator");</code></font>
<p>
<a name="29747"></a>
This string should consist of a single character, whose value is also available in 
the field <code>pathSeparatorChar</code>; the string is provided merely for convenience.
<p><a name="29748"></a>
<p><font size=+1><strong>22.24.4   </strong> <code>public static final char <code><b>pathSeparatorChar</b></code> = pathSeparator.charAt(0);</code></font>
<p>
<a name="29749"></a>
The first occurrence of this character in a string is sometimes assumed to separate 
a host name from a path name. On UNIX systems this character is typically <code>':'</code>.
<p><a name="29750"></a>
<p><font size=+1><strong>22.24.5   </strong> <code>public <code><b>File</b></code>(String path) throws NullPointerException</code></font>
<p>
<a name="29751"></a>
This constructor initializes a newly created <code>File</code> so that it represents the path indicated
by the argument <code>path</code>.
<p><a name="32569"></a>
If the <code>path</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29752"></a>
<p><font size=+1><strong>22.24.6   </strong> <code>public <code><b>File</b></code>(String dirname, String name)<br>throws NullPointerException</code></font>
<p>
<a name="29753"></a>
This constructor initializes a newly created <code>File</code> so that it represents the path 
whose directory part is specified by the argument <code>dirname</code> and whose file name 
part is specified by the argument <code>name</code>. If the <code>dirname</code> argument is <code>null</code>, the <code>name</code> 
is used as the path; otherwise the concatenation of <code>dirname</code>, the <code>separatorChar</code> 
<a href="javaio.doc22.html#29744">(&#167;22.24.2)</a>, and the <code>name</code> is used as the path.
<p><a name="32567"></a>
If the <code>name</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29757"></a>
<p><font size=+1><strong>22.24.7   </strong> <code>public <code><b>File</b></code>(File dir, String name)<br>throws NullPointerException</code></font>
<p>
<a name="29758"></a>
This constructor initializes a newly created <code>File</code> so that it represents the path 
whose directory part is specified by the <code>File</code> object <code>dir</code> and whose file name part 
is specified by the argument <code>name</code>.
<p><a name="32568"></a>
If the <code>name</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.<p>
<a name="29759"></a>
<p><font size=+1><strong>22.24.8   </strong> <code>public String <code><b>toString</b></code>()</code></font>
<p>
<a name="29760"></a>
The result is a <code>String</code> equal to the path represented by this <code>File</code> object.
<p><a name="29764"></a>
Overrides the <code>toString</code> method of <code>Object</code> <a href="javalang.doc1.html#1152">(&#167;20.1.2)</a>.<p>
<a name="29765"></a>
<p><font size=+1><strong>22.24.9   </strong> <code>public boolean <code><b>equals</b></code>(Object obj)</code></font>
<p>
<a name="29766"></a>
The result is <code>true</code> if and only if the argument is not <code>null</code> and is a <code>File</code> object that 
represents the same path as this <code>File</code> object. In other words, two <code>File</code> objects are 
equal if and only if the strings returned by the <code>getPath</code> method <a href="javaio.doc22.html#29786">(&#167;22.24.12)</a> are 
equal.
<p><a name="29773"></a>
Overrides the <code>equals</code> method of <code>Object</code> <a href="javalang.doc1.html#14865">(&#167;20.1.3)</a>.<p>
<a name="29774"></a>
<p><font size=+1><strong>22.24.10   </strong> <code>public int <code><b>hashCode</b></code>()</code></font>
<p>
<a name="29779"></a>
The hash code of this <code>File</code> object is equal to the exclusive OR of the hash code of 
its path string and the decimal value <code>1234321</code>:
<p><pre><a name="30545"></a>this.getPath().hashcode() ^ 1234321
</pre><a name="30544"></a>
Overrides the <code>hashCode</code> method of <code>Object</code> <a href="javalang.doc1.html#13784">(&#167;20.1.4)</a>.<p>
<a name="29780"></a>
<p><font size=+1><strong>22.24.11   </strong> <code>public String <code><b>getName</b></code>()</code></font>
<p>
<a name="29784"></a>
If the path string contains the <code>separatorChar</code> character <a href="javaio.doc22.html#29744">(&#167;22.24.2)</a>, this method 
returns the substring of the path that follows the last occurrence of the separator 
character; otherwise, the entire path string is returned.
<p><a name="29786"></a>
<p><font size=+1><strong>22.24.12   </strong> <code>public String <code><b>getPath</b></code>()</code></font>
<p>
<a name="29787"></a>
The result is a <code>String</code> equal to the path represented by this <code>File</code> object.
<p><a name="29788"></a>
<p><font size=+1><strong>22.24.13   </strong> <code>public String <code><b>getAbsolutePath</b></code>()</code></font>
<p>
<a name="29789"></a>
The result is a <code>String</code> equal to the result of converting to "absolute form" the path 
represented by this <code>File</code> object.
<p><a name="29790"></a>
<p><font size=+1><strong>22.24.14   </strong> <code>public String <code><b>getParent</b></code>()</code></font>
<p>
<a name="29791"></a>
If the path has a parent directory, a <code>String</code> representing the path of that parent 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -