StringWriter
In this chapter you will learn:
Use StringWriter
StringWriter
is character stream that collects its output in a string buffer.
import java.io.IOException;
import java.io.StringWriter;
/*from j a va2s.c o m*/
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
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » I/O