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.yiibai; 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