Java Writer write()方法

java.io.Writer.write(int c) 只写一个字符。要写入的字符被包含在给定整数值的低16位; 16个高序位被忽略。

1 语法

public void write(int c)

2 参数

c:int指定要写入的字符。

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.Writer.write(int c)方法的例子
 */
import java.io.*;

public class Demo {
    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

热门文章

优秀文章