Java BufferedWriter.write(char[] cbuf, int off, int len)方法範例
BufferedWriter
的Java BufferedWriter.write(char[] cbuf, int off, int len)
方法的語法如下。
public void write(char[] cbuf, int off, int len) throws IOException
在下面的程式碼中展示了如何使用BufferedWriter.write(char[] cbuf, int off, int len)
方法。
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
public class Main {
public static void main(String[] args) throws IOException {
char[] cbuf = "from tw511.com".toCharArray();
StringWriter sw = new StringWriter();
BufferedWriter bw = new BufferedWriter(sw);
bw.write(cbuf, 2, 5);
bw.flush();
StringBuffer sb = sw.getBuffer();
System.out.println(sb);
}
}
上面的程式碼生成以下結果。
om yi