|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.FileOutputStream
public class FileOutputStream
檔案輸出串流是用於將資料寫入 File 或 FileDescriptor 的輸出串流。檔案是否可用或能否可以被創建取決於基礎平臺。特別是某些平臺一次只允許一個 FileOutputStream(或其他檔案寫入物件)打開檔案進行寫入。在這種情況下,如果所涉及的檔案已經打開,則此類別中的建構子將失敗。
FileOutputStream 用於寫入諸如圖像資料之類別的原始位元組的串流。要寫入字元串流,請考慮使用 FileWriter。
File,
FileDescriptor,
FileInputStream| 建構子摘要 | |
|---|---|
FileOutputStream(File file)
創建一個向指定 File 物件表示的檔案中寫入資料的檔案輸出串流。 |
|
FileOutputStream(File file,
boolean append)
創建一個向指定 File 物件表示的檔案中寫入資料的檔案輸出串流。 |
|
FileOutputStream(FileDescriptor fdObj)
創建一個向指定檔案描述符處寫入資料的輸出檔案串流,該檔案描述符表示一個到檔案系統中的某個實際檔案的現有連接。 |
|
FileOutputStream(String name)
創建一個向具有指定名稱的檔案中寫入資料的輸出檔案串流。 |
|
FileOutputStream(String name,
boolean append)
創建一個向具有指定 name 的檔案中寫入資料的輸出檔案串流。 |
|
| 方法摘要 | |
|---|---|
void |
close()
關閉此檔案輸出串流並釋放與此串流有關的所有系統資源。 |
protected void |
finalize()
清理到檔案的連接,並確保在不再參考此檔案輸出串流時調用此串流的 close 方法。 |
FileChannel |
getChannel()
返回與此檔案輸出串流有關的唯一 FileChannel 物件。 |
FileDescriptor |
getFD()
返回與此串流有關的檔案描述符。 |
void |
write(byte[] b)
將 b.length 個位元組從指定 byte 陣列寫入此檔案輸出串流中。 |
void |
write(byte[] b,
int off,
int len)
將指定 byte 陣列中從偏移量 off 開始的 len 個位元組寫入此檔案輸出串流。 |
void |
write(int b)
將指定位元組寫入此檔案輸出串流。 |
| 從類別 java.io.OutputStream 繼承的方法 |
|---|
flush |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 建構子詳細資訊 |
|---|
public FileOutputStream(String name)
throws FileNotFoundException
FileDescriptor 物件來表示此檔案連接。
首先,如果有安全管理器,則用 name 作為參數調用 checkWrite 方法。
如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它,則拋出 FileNotFoundException。
name - 與系統有關的檔案名
FileNotFoundException - 如果檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒絕對檔案進行寫入存取。SecurityManager.checkWrite(java.lang.String)
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
name 的檔案中寫入資料的輸出檔案串流。如果第二個參數為 true,則將位元組寫入檔案末尾處,而不是寫入檔案開始處。創建一個新 FileDescriptor 物件來表示此檔案連接。
首先,如果有安全管理器,則用 name 作為參數調用 checkWrite 方法。
如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它,則拋出 FileNotFoundException。
name - 與系統有關的檔案名append - 如果為 true,則將位元組寫入檔案末尾處,而不是寫入檔案開始處
FileNotFoundException - 如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它。
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒絕對檔案進行寫入存取。SecurityManager.checkWrite(java.lang.String)
public FileOutputStream(File file)
throws FileNotFoundException
File 物件表示的檔案中寫入資料的檔案輸出串流。創建一個新 FileDescriptor 物件來表示此檔案連接。
首先,如果有安全管理器,則用 file 參數表示的路徑作為參數來調用 checkWrite 方法。
如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開,則拋出 FileNotFoundException。
file - 為了進行寫入而打開的檔案。
FileNotFoundException - 如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒絕對檔案進行寫入存取。File.getPath(),
SecurityException,
SecurityManager.checkWrite(java.lang.String)
public FileOutputStream(File file,
boolean append)
throws FileNotFoundException
File 物件表示的檔案中寫入資料的檔案輸出串流。如果第二個參數為 true,則將位元組寫入檔案末尾處,而不是寫入檔案開始處。創建一個新 FileDescriptor 物件來表示此檔案連接。
首先,如果有安全管理器,則用 file 參數表示的路徑作為參數來調用 checkWrite 方法。
如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它,則拋出 FileNotFoundException。
file - 為了進行寫入而打開的檔案。append - 如果為 true,則將位元組寫入檔案末尾處,而不是寫入檔案開始處
FileNotFoundException - 如果該檔案存在,但它是一個目錄,而不是一個常規檔案;或者該檔案不存在,但無法創建它;抑或因為其他某些原因而無法打開它
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒絕對檔案進行寫入存取。File.getPath(),
SecurityException,
SecurityManager.checkWrite(java.lang.String)public FileOutputStream(FileDescriptor fdObj)
首先,如果有安全管理器,則用檔案描述符 fdObj 參數作為參數來調用 checkRead 方法。
fdObj - 為進行寫入而打開的檔案描述符
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒絕對檔案描述符進行寫入存取SecurityManager.checkWrite(java.io.FileDescriptor)| 方法詳細資訊 |
|---|
public void write(int b)
throws IOException
OutputStream 的 write 方法。
OutputStream 中的 writeb - 要寫入的位元組。
IOException - 如果發生 I/O 錯誤。
public void write(byte[] b)
throws IOException
b.length 個位元組從指定 byte 陣列寫入此檔案輸出串流中。
OutputStream 中的 writeb - 資料。
IOException - 如果發生 I/O 錯誤。OutputStream.write(byte[], int, int)
public void write(byte[] b,
int off,
int len)
throws IOException
off 開始的 len 個位元組寫入此檔案輸出串流。
OutputStream 中的 writeb - 資料。off - 資料中的起始偏移量。len - 要寫入的位元組數。
IOException - 如果發生 I/O 錯誤。
public void close()
throws IOException
如果此串流有一個與之關聯的通道,則關閉該通道。
Closeable 中的 closeOutputStream 中的 closeIOException - 如果發生 I/O 錯誤。
public final FileDescriptor getFD()
throws IOException
FileDescriptor 物件,該檔案系統正被此 FileOutputStream 物件使用。
IOException - 如果發生 I/O 錯誤。FileDescriptorpublic FileChannel getChannel()
FileChannel 物件。
所返回通道的初始 java.nio.channels.FileChannel#position()position 將等於到目前為止從檔案中讀取的位元組數,除非此串流處於掛起網要,在這種情況下,它將等於檔案的大小。將位元組寫入此串流中會使通道的位置相應地增加。顯式地或通過寫入來更改通道的位置會更改此串流的檔案位置。
protected void finalize()
throws IOException
close 方法。
Object 中的 finalizeIOException - 如果發生 I/O 錯誤。FileInputStream.close()
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。