How to redirect output to a byte array?

I've Googled this, and looked around in the tutorials, but I haven't found a simple example of how to assign an output to a byte array. Maybe I'm just too much of a newbie to know how to navigate the documentation, but...

What I need is for this code (which does exactly what I want) to put the output in a byte array instead of in the file "test.txt". How do I accomplish that?

Thanks,

--gary

FileWriter writer =null;

try{

writer =new FileWriter("test.txt");

MinimalHTMLWriter htmlWriter =new MinimalHTMLWriter(writer,

(StyledDocument)textRegion.getDocument());

htmlWriter.write();

}

catch (IOException ex){

... etc...

[978 byte] By [fiziwiga] at [2007-10-3 2:52:13]
# 1
http://java.sun.com/j2se/1.5.0/docs/api/java/io/ByteArrayOutputStream.html
jverda at 2007-7-14 20:41:10 > top of Java-index,Java Essentials,New To Java...
# 2

And to get from a Writer (since the MinimalHTMLWriter takes a Writer) to a OutputStream use this:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/OutputStreamWriter.html

So create an OutputStreamWriter with a ByteArrayOutputStream as its argument. As the javadoc suggests, you could wrap that with a buffered writer just in case.

pthorsona at 2007-7-14 20:41:10 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks, That works fine!--gary
fiziwiga at 2007-7-14 20:41:10 > top of Java-index,Java Essentials,New To Java...