例子
以下示例显示java.io.CharArrayWriter.write(int c)方法的用法。
package com.jc2182;
import java.io.CharArrayWriter;
public class CharArrayWriterDemo {
public static void main(String[] args) {
int i = 0;
String str = "";
CharArrayWriter chw = null;
try {
// create character array writer
chw = new CharArrayWriter();
// from integer 65 to 69
for(i = 65; i<70; i++) {
// write integer to writer
chw.write(i);
// get the default character set value
str = chw.toString();
// print the string
System.out.println(str);
}
} catch(Exception e) {
// for any error
e.printStackTrace();
} finally {
// releases all system resources from writer
if(chw!=null)
chw.close();
}
}
}
让我们编译并运行以上程序,这将产生以下结果-