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


Java Java.io.PrintWriter.append( CharSequence csq )用法及代碼示例


描述

這個java.io.PrintWriter.append()方法將指定的字符序列附加到此編寫器。

聲明

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

public PrintWriter append(CharSequence csq)

參數

csq─ 要追加的字符序列。如果 csq 為空,則將四個字符 "null" 附加到此 writer。

返回值

此方法返回此編寫器。

異常

NA

示例

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

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo {
   public static void main(String[] args) {
      CharSequence sq1 = "Hello";
      CharSequence sq2 = " World";

      // create a new stream at system
      PrintWriter pw = new PrintWriter(System.out);

      // append the sequence
      pw.append(sq1);
      pw.append(sq2);

      // flush the writer
      pw.flush();
   }
}

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

Hello World

相關用法


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