| 類別 | 功能 | 典型構造 |
|---|---|---|
| DataInputStream | 讀取基本型別、字串 | new DataInputStream(new BufferedInputStream(new FileInputStream(f))) |
| BufferedInputStream | 緩衝讀取提升效能 | new BufferedInputStream(new FileInputStream(f), 8192) |
| LineNumberInputStream | 追蹤行號 | new LineNumberInputStream(new FileInputStream(f)) |
| PushbackInputStream | 單字節推回(編譯器掃描用) | new PushbackInputStream(new FileInputStream(f)) |
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
String line;
while ((line = in.readLine()) != null) { ... }
StringBufferInputStream mem = new StringBufferInputStream(str);
DataInputStream in = new DataInputStream(mem);
while (in.available() > 0) System.out.print((char) in.readByte());
LineNumberInputStream lnis = new LineNumberInputStream(new StringBufferInputStream(s2));
DataInputStream in = new DataInputStream(lnis);
while ((line = in.readLine()) != null) {
System.out.println(lnis.getLineNumber() + ": " + line);
}
readLine() 返回 null、read() 返回 -1、available() == 0、捕獲 EOFException 四種方式視場景選擇。