Java.io.PrintWriter.append(CharSequence csq, int start, int end) 方法



描述

java.io.PrintWriter.append() 方法將指定字元序列的子序列追加到此寫入器。

宣告

以下是 java.io.PrintWriter.append() 方法的宣告。

public PrintWriter append(CharSequence csq,int start,int end)

引數

  • csq - 要追加的字元序列。如果 csq 為 null,則將四個字元“null”追加到此寫入器。

  • start - 子序列中第一個字元的索引。

  • end - 子序列中最後一個字元之後的字元的索引。

返回值

此方法返回此寫入器。

異常

示例

以下示例演示了 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, 1, 3);
      pw.append(sq2, 1, 4);

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

讓我們編譯並執行上述程式,這將產生以下結果:

elWor
java_io_printwriter.htm
廣告

© . All rights reserved.