Java.io.OutputStream class in Java Last Updated : 12 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report This abstract class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink. Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output. Constructor and Description OutputStream() : Single Constructor Methods: void close() : Closes this output stream and releases any system resources associated with this stream. Syntax :public void close() throws IOException Throws: IOException void flush() : Flushes this output stream and forces any buffered output bytes to be written out. Syntax :public void flush() throws IOException Throws: IOException void write(byte[] b) : Writes b.length bytes from the specified byte array to this output stream. Syntax :public void write(byte[] b) throws IOException Parameters: b - the data. Throws: IOException void write(byte[] b, int off, int len) : Writes len bytes from the specified byte array starting at offset off to this output stream. Syntax :public void write(byte[] b, int off, int len) throws IOException Parameters: b - the data. off - the start offset in the data. len - the number of bytes to write. Throws: IOException abstract void write(int b) : Writes the specified byte to this output stream. Syntax :public abstract void write(int b) throws IOException Parameters: b - the byte. Throws: IOException Java import java.io.*; //Java program to demonstrate OutputStream class OutputStreamDemo { public static void main(String args[])throws Exception { OutputStream os = new FileOutputStream("file.txt"); byte b[] = {65, 66, 67, 68, 69, 70}; //illustrating write(byte[] b) method os.write(b); //illustrating flush() method os.flush(); //illustrating write(int b) method for (int i = 71; i <75 ; i++) { os.write(i); } os.flush(); //close the stream os.close(); } } Output : ABCDEFGHIJ Comment More infoAdvertise with us Next Article Java.io.ObjectOutputStream Class in Java | Set 1 C ChippingEye2766 Improve Article Tags : Java Practice Tags : Java Similar Reads Java.io.PipedInputStream class in Java Pipes in IO provides a link between two threads running in JVM at the same time. So, Pipes are used both as source or destination. PipedInputStream is also piped with PipedOutputStream. So, data can be written using PipedOutputStream and can be written using PipedInputStream.But, using both threads 5 min read Java.io.ObjectOutputStream Class in Java | Set 1 An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. The objects can be read (reconstituted) using an ObjectInputStream. Persistent storage of objects can be accomplished by using a file for the stream. Only objects that support the java.io.Serializable in 9 min read Java.io.PushbackInputStream class in Java Pushback is used on an input stream to allow a byte to be read and then returned (i.e, "pushed back") to the stream. The PushbackInputStream class implements this idea. It provides a mechanism "peek" at what is coming from an input stream without disrupting it. It extends FilterInputStream.Fields: p 7 min read Java.io.ObjectInputStream Class in Java | Set 1 ObjectInputStream Class deserializes the primitive data and objects previously written by ObjectOutputStream. Both ObjectOutputStream and ObjectInputStream are used as it provides storage for graphs of object.It ensures that the object it is working for, matches the classes of JVM i.e Java Virtual M 9 min read Java.io.ObjectInputStream Class in Java | Set 2 Java.io.ObjectInputStream Class in Java | Set 1 Note : Java codes mentioned in this article won't run on Online IDE as the file used in the code doesn't exists online. So, to verify the working of the codes, you can copy them to your System and can run it over there. More Methods of ObjectInputStrea 6 min read Java.io.Printstream Class in Java | Set 2 Java.io.Printstream Class in Java | Set 1More Methods: PrintStream printf(Locale l, String format, Object... args) : A convenience method to write a formatted string to this output stream using the specified format string and arguments. Syntax :public PrintStream printf(Locale l, String format, Obje 6 min read Like