当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.io.PrintWriter.flush()用法及代码示例



描述

这个java.io.PrintWriter.flush()方法刷新流。

声明

以下是声明java.io.PrintWriter.flush()方法。

public void flush()

参数

NA

返回值

此方法不返回值。

异常

NA

示例

下面的例子展示了使用java.io.PrintWriter.flush()方法。

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo {
   public static void main(String[] args) {
      String s = "Hello World";
      
      try {
         // create a new stream at specified file
         PrintWriter pw = new PrintWriter(System.out);

         // write the string in the file
         pw.write(s);

         // flush the writer
         pw.flush();
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

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

Hello World

相关用法


注:本文由纯净天空筛选整理自 Java.io.PrintWriter.flush() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。