Java Writer close()方法
java.io.Writer.close() 关闭流。
1 语法
public abstract void close()
2 参数
无
3 返回值
无
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.Writer.close()方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
String s = "Hello World";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a string
writer.append(s);
// flush the writer
writer.flush();
// append a new string
writer.append("\nThis is an example");
// flush and close the stream
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
输出结果为:
Hello World
This is an example
热门文章
优秀文章