Java.io.Writer.write() 方法
描述
java.io.Writer.write(int c) 方法写入单个字符。 要写入的字符包含在给定整数值的低 16 位中; 忽略高 16 位。
声明
以下是 java.io.Writer.write() 方法的声明。
public void write(int c)
参数
c − int 指定要写入的字符。
返回值
此方法不返回值。
异常
IOException − 如果发生 I/O 错误。
示例
下面的例子展示了 java.io.Writer.write() 方法的使用。
package com.tutorialspoint;
import java.io.*;
public class WriterDemo {
public static void main(String[] args) {
int c = 70;
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// write an int that will be printed as ASCII
writer.write(c);
// flush the writer
writer.flush();
// write another int that will be printed as ASCII
writer.write(71);
// flush the stream again
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
FG

