目录

void close()

描述 (Description)

java.io.StringWriter.close()方法关闭StringWriter但没有效果。 在关闭流之后可以调用此类中的方法,而不会生成IOException。

声明 (Declaration)

以下是java.io.StringWriter.close()方法的声明。

public void close()

参数 (Parameters)

NA

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

IOException - 如果发生I/O错误

例子 (Example)

以下示例显示了java.io.StringWriter.close()方法的用法。

package com.iowiki;
import java.io.*;
public class StringWriterDemo {
   public static void main(String[] args) {
      // create a new writer
      StringWriter sw = new StringWriter();
      // create a new sequence
      String s = "Hello world";
      // write a string
      sw.write(s);
      // print result
      System.out.println("" + sw.toString());
      try {
         // close the writer
         sw.close();
      } catch (IOException ex) {
         ex.printStackTrace();;
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Hello World
↑回到顶部↑
WIKI教程 @2018