java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.Writer | ||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.StringWriter | ||||||||||||||||||||||||||||||||||||||||||||||||
A character stream that collects its output in a string buffer.
Constructor | Summary |
---|---|
StringWriter() | Create a new string writer using the default initial string-buffer size. |
StringWriter(int initialSize) | Create a new string writer using the specified initial string-buffer size. |
Return | Method | Summary |
---|---|---|
StringWriter | append(char c) | Appends the specified character to this writer. |
StringWriter | append(CharSequence csq) | Appends the specified character sequence to this writer. |
StringWriter | append(CharSequence csq, int start, int end) | Appends a subsequence of the specified character sequence to this writer. |
void | close() | Closing a StringWriter has no effect. |
void | flush() | Flush the stream. |
StringBuffer | getBuffer() | Return the string buffer itself. |
String | toString() | Return the buffer's current value as a string. |
void | write(char[] cbuf, int off, int len) | Write a portion of an array of characters. |
void | write(int c) | Write a single character. |
void | write(String str) | Write a string. |
void | write(String str, int off, int len) | Write a portion of a string. |
import java.io.IOException;
import java.io.StringWriter;
public class Main {
public static void main(String args[]) throws IOException {
StringWriter outStream = new StringWriter();
String s = "This is a test from j a va2s.com.";
for (int i = 0; i < s.length(); ++i)
outStream.write(s.charAt(i));
System.out.println("outstream: " + outStream);
System.out.println("size: " + outStream.toString().length());
}
}
The output:
outstream: This is a test from j a va2s.com.
size: 33
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |