Java String Writer转换为String

本文介绍如何将writer转换为string.

package com.beginnersbook.string;
import java.io.StringWriter;

public class WriterToString {
    public static void main(String args[]){
        // create a new writer
          StringWriter sw = new StringWriter();

          // append a char       
          sw.append("abc");
          sw.append(" xyz");

          String str = sw.toString();
          System.out.println(str);
    }
}

输出:

abc xyz

赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址