OutputStream
is an abstract class used to write byte-oriented data to output destinations like files, memory or network connections.
java.io
package.
write()
to send data to output destinations.
FileOutputStream fos = new FileOutputStream("output.txt");
fos.write(65); // writes 'A'
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(65);
byte[] data = baos.toByteArray();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("file.txt"));
bos.write(65);
DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.bin"));
dos.writeInt(123);
PrintStream ps = new PrintStream(new FileOutputStream("log.txt"));
ps.println("Hello World");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("object.ser"));
oos.writeObject(new MyClass());
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
pos.write(65);
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.