slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
I/O PowerPoint Presentation
Download Presentation
I/O

Loading in 2 Seconds...

play fullscreen
1 / 31

I/O - PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on

I/O. java.io 套件 Stream 串流 : 資料由一端接連不斷地傳向另一端 Source Stream Sink Stream. 以 byte 為單位的資料流 8bits InputStream OutputStream 以 character 為單位的資料流 16bits(Unicode) Reader Writer. Stream Classes. Node. 節點 (Node): 資料讀取的來源或寫入的目的地. Node Stream 類別. 讀取及寫入資料演算法. InputStream 類別. 建構子

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'I/O' - rashad-herring


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1
I/O
  • java.io套件
  • Stream
    • 串流:資料由一端接連不斷地傳向另一端
    • Source Stream
    • Sink Stream
slide2
以byte為單位的資料流
    • 8bits
    • InputStream
    • OutputStream
  • 以character為單位的資料流
    • 16bits(Unicode)
    • Reader
    • Writer
slide4
Node
  • 節點(Node):
    • 資料讀取的來源或寫入的目的地
inputstream
InputStream類別
  • 建構子

public InputStream()

  • 常用方法

public abstract int read() throws IOException

public int read(byte[] b) throws IOException

public int read(byte[] b, int off, int len) throws IOException

slide9
public int available() throws IOException

public long skip(long n) throws IOException

public void mark(int readlimit)

public void reset() throws IOException

public boolean markSupported()

public void close() throws IOException

outputstream
OutputStream類別
  • 建構子

public OutputStream()

  • 常用方法

public abstract void write(int b) throws IOException

public void write(byte[] b) throws IOException

public void write(byte[] b, int off, int len) throws IOException

public void flush() throws IOException

public void close() throws IOException

reader
Reader類別
  • 建構子

protected Reader()

  • 常用方法

public int read() throws IOException

public int read(char[] c) throws IOException

public abstract int read(char[] c, int off, int len) throws IOException

slide13
public boolean ready() throws IOException

public long skip(long n) throws IOException

public void mark(int readAheadLimit )

public void reset() throws IOException

public boolean markSupported()

public abstract void close() throws IOException

writer
Writer類別
  • 建構子

protected Writer()

  • 常用方法

public void write(int c) throws IOException

public void write(char[] c) throws IOException

public abstract void write(char[] c, int off, int len) throws IOException

slide15
public void write(Stringstr) throws IOException

public void write(Stringstr, intoff, intlen ) throws IOException

public abstract void flush() throws IOException

public abstract void close() throws IOException

fileinputstream

java.lang.Object

java.io.InputStream

java.io.fileInputStream

FIleInputStream類別
  • 繼承關係
  • 建構子

public FileInputStream(String name) throws FileNotFoundException

public FileInputStream(File file) throws FileNotFoundException

slide19
常用方法

public int read() throws IOException

public int read(byte[] b) throws IOException

public int read(byte[] b, int off, int len) throws IOException

public long skip(long n) throws IOException

public int available() throws IOException

public void close() throws IOException

protected void finalize() throws IOException

filereader

java.lang.Object

java.io.Reader

java.io.InputStreamReader

java.io.FileReader

FileReader類別

若讀的是英文則補成2bytes,若讀的是中文則直接讀兩bytes包成unicode,所以FileReader 跟 io.Reader之間還會有個InputStreamReader

  • 繼承關係
  • 建構子

public FileReader(String name) throws FileNotFoundException

public FileReader(File file) throws FileNotFoundException

fileoutputstream

java.lang.Object

java.io.OutputStream

java.io.fileOutputStream

FileOutputStream類別
  • 繼承關係
  • 建構子

public FileOutputStream(Stringname, booleanappend) throws FileNotFoundException

public FileOutputStream(Filefile, booleanappend) throws FileNotFoundException

filewriter

java.lang.Object

java.io.Reader

java.io.OutputStreamWriter

java.io.FileWriter

FileWriter類別
  • 繼承關係
  • 建構子

public FileWriter(String fileName, boolean append) throws IOException

public FileWriter(File file, boolean append) throws IOException

slide23

Data Source

Program

資料輸入串流

資料輸入Filter

Data Source

Program

資料輸出串流

資料輸出Filter

資料串流連結

因可能要一次讀一行,而不是一次1byte or 1 char,所以每次讀寫都先放到 filter,再由 pgm 來讀一行,或寫一行到出去,再轉成byte or char寫出.

  • Filter:
    • 將資料流連結至特殊的串流,以便使用特定的方法來存取
serialization
物件序列化(Serialization)
  • Serialization
    • 直接把物件作輸出入的處理
    • 物件內容輸出到file
  • 物件序列化步驟
    • implements Serializable
    • ObjectOutputStream
    • ObjectInputStream
serializable
Serializable
  • 要輸出的物件類別需實作Serializable
    • 標記介面 Maker interface

只有介面宣告,內部完全沒有任何常數或方法宣告

  • transient
    • 某個屬性不想被序列化,加上transient修飾子
objectoutputstream

java.lang.Object

java.io.OutputStream

java.io.ObjectOutputStream

ObjectOutputStream
  • 繼承關係
  • 建構子

public ObjectOutputStream(OutputStream out) throws IOException

slide29
常用方法

public final void writeObject(Object obj) throws IOException

public void writeBoolean(boolean val) throws IOException

public void writeChar(int val) throws IOException

public void writeInt(int val) throws IOException

public void writeDouble(double val) throws IOException

public void writeChars(String str) throws IOException

objectinputstream

java.lang.Object

java.io.InputStream

java.io.ObjectInputStream

ObjectInputStream
  • 繼承關係
  • 建構子

public ObjectInputStream(InputStream in) throws IOException

slide31
常用方法

public final Object readObject() throws IOException, ClassNotFoundException

public boolean readBoolean() throws IOException

public char readChar() throws IOException

public int readInt() throws IOException

public double readDouble() throws IOException