java.io.BufferedWriter.write(char[] cbuf, int off, int len) 方法写入的字符缓冲区一块到writer。抵消了从开始读取字符,len是从字符缓冲区的部分的长度。
更多教程请访问http://www.manongzj.com
声明
以下是声明java.io.BufferedWriter.write(char[] cbuf, int off, int len) 方法:
public void write(char[] cbuf, int off, int len)
参数
-
cbuf -- 要写入的字符数组
-
off -- 关闭偏移开始读取字符缓冲区
-
len -- 被写入到该流的字符数
返回值
此方法不返回任何值。
异常
-
IOException -- 如果发生I/ O错误。
例子
下面的例子显示java.io.BufferedWriter.write(char[] cbuf, int off, int len) 方法。
package com.yiibai;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
public class BufferedWriterDemo {
public static void main(String[] args) throws IOException {
StringWriter sw = null;
BufferedWriter bw = null;
char[] cbuf = "ABCDEFGHIJKLMN".toCharArray();
try{
// create string writer
sw = new StringWriter();
//create buffered writer
bw = new BufferedWriter(sw);
// write from specified character buffer to stream
bw.write(cbuf, 2, 5);
// forces out the characters to string writer
bw.flush();
// string buffer is created
StringBuffer sb = sw.getBuffer();
//prints the string
System.out.println(sb);
}catch(IOException e){
// if I/O error occurs
e.printStackTrace();
}finally{
// releases any system resources associated with the stream
if(sw!=null)
sw.close();
if(bw!=null)
bw.close();
}
}
}
让我们来编译和运行上面的程序,这将产生以下结果:
CDEFG