Input Stream read File Reader int read int

  • Slides: 14
Download presentation

Input. Stream类提供的方法 § 三个基本的read方法: File. Reader int read() int read(byte[] buffer, int offset, int

Input. Stream类提供的方法 § 三个基本的read方法: File. Reader int read() int read(byte[] buffer, int offset, int length) § 其它方法: void close() int available() skip(long n) boolean mark. Supported() void mark(int readlimit) void reset()

Output. Stream类提供的方法 § 三个基本的write方法: void write(int c) void write(byte[] buffer, int offset, int length)

Output. Stream类提供的方法 § 三个基本的write方法: void write(int c) void write(byte[] buffer, int offset, int length) § 其它方法 void close() void flush()

Reader类提供的方法 § 三个基本的read方法: int read() int read(char[] cbuf, int offset, int length) § 其它方法

Reader类提供的方法 § 三个基本的read方法: int read() int read(char[] cbuf, int offset, int length) § 其它方法 void close() boolean ready() skip(long n) boolean mark. Supported() void mark(int read. Ahead. Limit) void reset()

Writer类提供的方法 § 三个基本的write方法: void write(int c) void write(char[] cbuf, int offset, int length) void

Writer类提供的方法 § 三个基本的write方法: void write(int c) void write(char[] cbuf, int offset, int length) void write(String string, int offset, int length) § 其它方法 void close() void flush()

节点流类型(Node Streams) 类 型 字符流 字节流 File. Reader File. Writer File. Input. Stream File.

节点流类型(Node Streams) 类 型 字符流 字节流 File. Reader File. Writer File. Input. Stream File. Output. Stream Memory Array Char. Array. Reader Char. Array. Writer Byte. Array. Input. Stream Byte. Array. Output. Stream Memory String. Reader String. Writer Piped. Reader Piped. Writer Piped. Input. Stream Piped. Output. Stream

节点流应用举例--文件复制 import java. io. *; public class Test 1 { public static void main(String[]

节点流应用举例--文件复制 import java. io. *; public class Test 1 { public static void main(String[] args) { try { File. Reader input = new File. Reader("Test 1. java"); File. Writer output = new File. Writer("temp. txt"); int read = input. read(); while ( read != -1 ) { output. write(read); read = input. read(); } input. close(); output. close(); } catch (IOException e) { System. out. println(e); } } }

缓冲功能处理流举例 import java. io. *; public class Test 2 { public static void main(String[]

缓冲功能处理流举例 import java. io. *; public class Test 2 { public static void main(String[] args) { try { File. Reader input = new File. Reader("Test 2. java"); Buffered. Reader br = new Buffered. Reader(input); File. Writer output = new File. Writer("temp. txt"); Buffered. Writer bw = new Buffered. Writer(output); String s = br. read. Line(); while ( s!=null ) { bw. write(s); bw. new. Line(); s = br. read. Line(); } br. close(); bw. close(); } catch (IOException e) { e. print. Stack. Trace(); } } }