Example usage for java.io StringWriter StringWriter

List of usage examples for java.io StringWriter StringWriter

Introduction

In this page you can find the example usage for java.io StringWriter StringWriter.

Prototype

public StringWriter() 

Source Link

Document

Create a new string writer using the default initial string-buffer size.

Usage

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // append a char       
    System.out.println(sw.append("a"));
    System.out.println(sw.append("b"));

    System.out.println(sw.toString());
}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // write a string
    sw.write("tutorial from java2s.com");

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // write integers that correspond to ascii code
    sw.write(70);//w w  w  .  ja  v  a 2s. c om
    sw.write(76);

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // write a string
    sw.write("tutorial from java2s.com");

    // print result by getting the buffer
    System.out.println("" + sw.getBuffer());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // create a new sequence
    String s = "from java2s.com";

    // write a string
    sw.write(s);/* w  w w . j a v  a 2s.c  o  m*/

    // flush the writer
    sw.flush();

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    CharSequence sq = "tutorial from java2s.com";

    // append sequence
    sw.append(sq, 0, 5);/*w  w  w.ja  v a2s .  c om*/

    System.out.println(sw.toString());

    // append second sequence
    sw.append(sq, 6, 5);

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // create two new sequences
    CharSequence sq1 = "Hello";
    CharSequence sq2 = " World from java2s.com";

    // append sequence
    sw.append(sq1);//from w w  w .j  a v  a  2 s . co m

    System.out.println(sw.toString());

    // append second sequence
    sw.append(sq2);

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // create a new sequence
    String s = "Hello from java2s.com";

    // write a string
    sw.write(s);//  ww  w  . j a va  2  s.  c o m

    System.out.println(sw.toString());

    try {
        // close the writer
        sw.close();
    } catch (IOException ex) {
        ex.printStackTrace();
        ;
    }

}

From source file:Main.java

public static void main(String[] args) {

    char c = 'b';

    StringWriter sw = new StringWriter();

    // write chars
    sw.write('a');
    sw.write(c);//from  w ww  . j av a  2 s . c o  m

    System.out.println(sw.toString());

}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";

    StringWriter sw = new StringWriter();

    // write strings
    sw.write(s);//from  w w w  . jav a  2s  .com
    sw.write(" World");

    System.out.println(sw.toString());

}