📄 javaio.doc14.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.doc13.html">Prev</a> | <a href="javaio.doc15.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
<a name="29496"></a>
<center><h1>22.16 The Class <code>java.io.FileOutputStream</code></h1></center>
<a name="33833"></a>
A file output stream writes output bytes to a file in a file system. What files are
available or may be created depends on the host environment.
<p><pre><a name="29497"></a>public class <code><b>FileOutputStream</b></code> extends OutputStream {
<a name="29498"></a> public <code><b>FileOutputStream</b></code>(String path)
<a name="30523"></a> throws SecurityException, FileNotFoundException;
<a name="29499"></a> public <code><b>FileOutputStream</b></code>(File file)
<a name="30524"></a> throws SecurityException, FileNotFoundException;
<a name="29500"></a> public <code><b>FileOutputStream</b></code>(FileDescriptor fdObj)
<a name="30533"></a> throws SecurityException;
<a name="46165"></a> public final FileDescriptor <code><b>getFD</b></code>() throws IOException;
<a name="29501"></a> public void <code><b>write</b></code>(int b) throws IOException;
<a name="29502"></a> public void <code><b>write</b></code>(byte[] b)
<a name="32391"></a> throws IOException, NullPointerException;
<a name="29503"></a> public void <code><b>write</b></code>(byte[] b, int off, int len)
<a name="29504"></a> throws IOException, NullPointerException,
<a name="32394"></a> IndexOutOfBoundsException;
<a name="29505"></a> public void <code><b>close</b></code>() throws IOException;
<a name="29507"></a> protected void <code><b>finalize</b></code>() throws IOException;
<a name="29508"></a>}
</pre><a name="29510"></a>
<p><font size=+1><strong>22.16.1 </strong> <code>public <code><b>FileOutputStream</b></code>(String path)<br>throws SecurityException, <code>FileNotFound</code>Exception</code></font>
<p>
<a name="29511"></a>
This constructor initializes a newly created <code>FileOutputStream</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="29515"></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 <code>path</code> argument as its argument.<p>
<a name="29516"></a>
If the actual file cannot be opened, a <code>FileNotFoundException</code> is thrown.<p>
<a name="29518"></a>
<p><font size=+1><strong>22.16.2 </strong> <code>public <code><b>FileOutputStream</b></code>(File file)<br>throws SecurityException, <code>FileNotFound</code>Exception</code></font>
<p>
<a name="29519"></a>
This constructor initializes a newly created <code>FileOutputStream</code> by opening a
connection to an actual file, the file named by <code>file</code> in the file system. A new
<code>FileDescriptor</code> object is created to represent this file connection.
<p><a name="29523"></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 the <code>file</code> argument as its argument.<p>
<a name="29524"></a>
If the actual file cannot be opened, a <code>FileNotFoundException</code> is thrown.<p>
<a name="29525"></a>
<p><font size=+1><strong>22.16.3 </strong> <code>public <code><b>FileOutputStream</b></code>(FileDescriptor fdObj)<br>throws <code>SecurityException</code></code></font>
<p>
<a name="30502"></a>
This constructor initializes a newly created <code>FileOutputStream</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="30494"></a>
First, if there is a security manager, its <code>checkWrite</code> method <a href="javalang.doc16.html#14116">(§20.17.20)</a> is called with the file descriptor <code>fdObj</code> argument as its argument.<p>
<a name="29526"></a>
<p><font size=+1><strong>22.16.4 </strong> <code>public final FileDescriptor <code><b>getFD</b></code>() throws IOException</code></font>
<p>
<a name="30440"></a>
This method returns the <code>FileDescriptor</code> object <a href="javaio.doc23.html#29890">(§22.26)</a> that represents the connection
to the actual file in the file system being used by this <code>FileOutputStream</code>.
<p><a name="29527"></a>
<p><font size=+1><strong>22.16.5 </strong> <code>public void <code><b>write</b></code>(int b) throws IOException</code></font>
<p>
<a name="29528"></a>
The byte for this operation is written to the actual file to which this file output
stream is connected.
<p><a name="29532"></a>
Implements the <code>write</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29411">(§22.15.1)</a>.<p>
<a name="29533"></a>
<p><font size=+1><strong>22.16.6 </strong> <code>public void <code><b>write</b></code>(byte[] b)<br>throws IOException, NullPointerException</code></font>
<p>
<a name="29534"></a>
Bytes for this operation are written to the actual file to which this file output
stream is connected.
<p><a name="29538"></a>
Overrides the <code>write</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29419">(§22.15.2)</a>.<p>
<a name="29539"></a>
<p><font size=+1><strong>22.16.7 </strong> <code>public void <code><b>write</b></code>(byte[] b, int off, int len)<br>throws IOException, NullPointerException,      IndexOutOfBoundsException</code></font>
<p>
<a name="29540"></a>
Bytes for this operation are written to the actual file to which this file output
stream is connected.
<p><a name="29544"></a>
Overrides the <code>write</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29426">(§22.15.3)</a>.<p>
<a name="29545"></a>
<p><font size=+1><strong>22.16.8 </strong> <code>public void <code><b>close</b></code>() throws IOException</code></font>
<p>
<a name="29546"></a>
This file output stream is closed and may no longer be used for writing bytes.
<p><a name="29550"></a>
Overrides the <code>close</code> method of <code>OutputStream</code> <a href="javaio.doc13.html#29445">(§22.15.5)</a>.<p>
<a name="29551"></a>
<p><font size=+1><strong>22.16.9 </strong> <code>protected void <code><b>finalize</b></code>() throws IOException</code></font>
<p>
<a name="29552"></a>
A <code>FileOutputStream</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.doc13.html">Prev</a> | <a href="javaio.doc15.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 + -