Java CharArrayReader close()方法

java.io.CharArrayReader.close() 用于关闭流。

1 语法

public void close()

2 参数

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.CharArrayReader.close()方法的例子
 */
import java.io.CharArrayReader;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) {
        CharArrayReader car = null;
        char[] ch = {'H', 'E', 'L', 'L', 'O'};

        try {
            // create new character array reader
            car = new CharArrayReader(ch);

            // closes the character array stream
            car.close();

            // read the character array stream
            car.read();

        } catch(IOException e) {
            // if I/O error occurs
            System.out.print("Stream is already closed");
        } finally {
            // releases any system resources associated with the stream
            if(car!=null)
                car.close();
        }
    }
}

输出结果为:

Stream is already closed

热门文章

优秀文章