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

📄 javaio.doc2.html

📁 java语言规范
💻 HTML
字号:
<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.doc1.html">Prev</a> | <a href="javaio.doc3.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
 
<a name="28230"></a>
<center><h1>22.4  The Class  <code>java.io.FileInputStream</code></h1></center>
<a name="33503"></a>
A file input stream obtains input bytes from a file in a file system. What files are 
available depends on the host environment.
<p><pre><a name="28231"></a>public class <code><b>FileInputStream</b></code> extends InputStream  {
<a name="28232"></a>	public <code><b>FileInputStream</b></code>(String path)
<a name="28233"></a>		throws SecurityException, FileNotFoundException;
<a name="28234"></a>	public <code><b>FileInputStream</b></code>(File file)
<a name="28235"></a>		throws SecurityException, FileNotFoundException;
<a name="28236"></a>	public <code><b>FileInputStream</b></code>(FileDescriptor fdObj)
<a name="30480"></a>		throws SecurityException;
<a name="28237"></a>	public native int <code><b>read</b></code>() throws IOException;
<a name="28238"></a>	public int <code><b>read</b></code>(byte[] b)
<a name="32297"></a>		throws IOException, NullPointerException;
<a name="28239"></a>	public int <code><b>read</b></code>(byte[] b, int off, int len)
<a name="28240"></a>		throws IOException, NullPointerException,
<a name="32300"></a>			IndexOutOfBoundsException;
<a name="28241"></a>	public native long <code><b>skip</b></code>(long n) throws IOException;
<a name="28242"></a>	public native int <code><b>available</b></code>() throws IOException;
<a name="28243"></a>	public native void <code><b>close</b></code>() throws IOException;
<a name="28244"></a>	public final FileDescriptor <code><b>getFD</b></code>() throws IOException;
<a name="28245"></a>	protected void <code><b>finalize</b></code>() throws IOException;
<a name="28246"></a>}
</pre><a name="28248"></a>
<p><font size=+1><strong>22.4.1   </strong> <code>public <code><b>FileInputStream</b></code>(String path)<br>throws SecurityException, FileNotFoundException</code></font>
<p>
<a name="28249"></a>
This constructor initializes a newly created <code>FileInputStream</code> by opening a connection
to an actual file, the file named by the path name <code>path</code> in the file system. 
A new <code>FileDescriptor</code> object is created to represent this file connection.
<p><a name="28253"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(&#167;20.17.19)</a> is called with the <code>path</code> argument as its argument.<p>
<a name="28254"></a>
If the actual file cannot be opened, a <code>FileNotFoundException</code> is thrown.<p>
<a name="28256"></a>
<p><font size=+1><strong>22.4.2   </strong> <code>public <code><b>FileInputStream</b></code>(File file)<br>throws SecurityException, FileNotFoundException</code></font>
<p>
<a name="28257"></a>
This constructor initializes a newly created <code>FileInputStream</code> by opening a connection
to an actual file, the file named by the <code>File</code> object <code>file</code> in the file system. 
A new <code>FileDescriptor</code> object is created to represent this file connection.
<p><a name="28261"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14115">(&#167;20.17.19)</a> is called with the path represented by the <code>file</code> argument as its argument.<p>
<a name="28262"></a>
If the actual file cannot be opened, a <code>FileNotFoundException</code> is thrown.<p>
<a name="28263"></a>
<p><font size=+1><strong>22.4.3   </strong> <code>public <code><b>FileInputStream</b></code>(FileDescriptor fdObj)<br>throws SecurityException</code></font>
<p>
<a name="30444"></a>
This constructor initializes a newly created <code>FileInputStream</code> by using the file 
descriptor <code>fdObj</code>, which represents an existing connection to an actual file in the 
file system.
<p><a name="30448"></a>
First, if there is a security manager, its <code>checkRead</code> method <a href="javalang.doc16.html#14114">(&#167;20.17.18)</a> is called with the file descriptor <code>fdObj</code> as its argument.<p>
<a name="28264"></a>
<p><font size=+1><strong>22.4.4   </strong> <code>public final FileDescriptor <code><b>getFD</b></code>() throws IOException</code></font>
<p>
<a name="30431"></a>
This method returns the <code>FileDescriptor</code> object <a href="javaio.doc23.html#29890">(&#167;22.26)</a> that represents the connection
to the actual file in the file system being used by this <code>FileInputStream</code>.
<p><a name="28265"></a>
<p><font size=+1><strong>22.4.5   </strong> <code>public int <code><b>read</b></code>() throws IOException;</code></font>
<p>
<a name="28266"></a>
The byte for this operation is read from the actual file with which this file input 
stream is connected.
<p><a name="28270"></a>
Implements the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28142">(&#167;22.3.1)</a>.<p>
<a name="28271"></a>
<p><font size=+1><strong>22.4.6   </strong> <code>public int <code><b>read</b></code>(byte[] b)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="28272"></a>
Bytes for this operation are read from the actual file with which this file input 
stream is connected.
<p><a name="28276"></a>
Overrides the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28150">(&#167;22.3.2)</a>.<p>
<a name="28277"></a>
<p><font size=+1><strong>22.4.7   </strong> <code>public int <code><b>read</b></code>(byte[] b, int off, int len)<br>throws IOException, NullPointerException,  &#32; &#32; &#32;IndexOutOfBoundsException</code></font>
<p>
<a name="28278"></a>
Bytes for this operation are read from the actual file with which this file input 
stream is connected.
<p><a name="28282"></a>
Overrides the <code>read</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28164">(&#167;22.3.3)</a>.<p>
<a name="28283"></a>
<p><font size=+1><strong>22.4.8   </strong> <code>public long <code><b>skip</b></code>(long n) throws IOException</code></font>
<p>
<a name="28284"></a>
Bytes for this operation are read from the actual file with which this file input 
stream is connected.
<p><a name="28288"></a>
Overrides the <code>skip</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28178">(&#167;22.3.4)</a>.<p>
<a name="28289"></a>
<p><font size=+1><strong>22.4.9   </strong> <code>public int <code><b>available</b></code>() throws IOException</code></font>
<p>
<a name="28293"></a>
Overrides the <code>available</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28182">(&#167;22.3.5)</a>.
<p><a name="28294"></a>
<p><font size=+1><strong>22.4.10   </strong> <code>public void <code><b>close</b></code>() throws IOException</code></font>
<p>
<a name="28295"></a>
This file input stream is closed and may no longer be used for reading bytes.
<p><a name="28299"></a>
Overrides the <code>close</code> method of <code>InputStream</code> <a href="javaio.doc1.html#28187">(&#167;22.3.6)</a>.<p>
<a name="28300"></a>
<p><font size=+1><strong>22.4.11   </strong> <code>protected void <code><b>finalize</b></code>() throws IOException</code></font>
<p>
<a name="28301"></a>
A <code>FileInputStream</code> uses finalization to clean up the connection to the actual 
file.
<p>

<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javaio.doc1.html">Prev</a> | <a href="javaio.doc3.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 &#169 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 + -