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
java_io_writer.htm
廣告
© . All rights reserved.