當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.io.PrintWriter.setError()用法及代碼示例


描述

這個java.io.PrintWriter.setError()method 指示發生了錯誤。此方法將導致 checkError() 的後續調用返回 true,直到調用 clearError()。

聲明

以下是聲明java.io.PrintWriter.setError()方法。

protected void setError()

參數

NA

返回值

此方法不返回值。

異常

NA

示例

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

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo extends PrintWriter {

   public PrintWriterDemo(OutputStream out) {
      super(System.out);
   }

   public static void main(String[] args) {
      String s = "Hello World";

      // create a new writer
      PrintWriterDemo pw = new PrintWriterDemo(System.out);

      // write substrings
      pw.write(s, 0, 5);
      pw.write(s, 6, 5);

      // flush the writer
      pw.flush();

      // set the error state
      pw.setError();
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果——

HelloWorld

相關用法


注:本文由純淨天空篩選整理自 Java.io.PrintWriter.setError() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。