PrintStream write(byte[], int, int) method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The write(byte[], int, int) method of PrintStream Class in Java is used to write a specified portion of the specified byteacter array on the stream. This byteacter array is taken as a parameter. The starting index and length of byteacters to be written are also taken as parameters. Syntax: public void write(byte[] byteArray, int startingIndex, int lengthOfCharArray) Parameters: This method accepts three mandatory parameters: byteArray which is the byteacter array to be written in the Stream. startingIndex which is the starting index from which the portion of byteacter is to taken. lengthOfCharArray which is the length of byteacters to be written on the stream. Return Value: This method do not returns any value. Below methods illustrates the working of write(byte[], int, int) method: Program 1: Java // Java program to demonstrate // PrintStream write(byte[], int, int) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a PrintStream instance PrintStream stream = new PrintStream(System.out); // Get the byteacter array // to be written in the stream byte[] byteArray = { 65, 66, 67 }; // Get the starting index int startingIndex = 0; // Get the length of byte int lengthOfCharArray = 1; // Write the portion of the byteArray // to this stream using write() method // This will put the byteArray in the stream // till it is printed on the console stream.write(byteArray, startingIndex, lengthOfCharArray); stream.flush(); } catch (Exception e) { System.out.println(e); } } } Output: A Program 2: Java // Java program to demonstrate // PrintStream write(byte[], int, int) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a PrintStream instance PrintStream stream = new PrintStream(System.out); // Get the byteacter array // to be written in the stream byte[] byteArray = { 97, 98, 99 }; // Get the starting index int startingIndex = 2; // Get the length of byte int lengthOfCharArray = 1; // Write the portion of the byteArray // to this stream using write() method // This will put the byteArray in the stream // till it is printed on the console stream.write(byteArray, startingIndex, lengthOfCharArray); stream.flush(); } catch (Exception e) { System.out.println(e); } } } Output: c Comment More infoAdvertise with us Next Article PrintStream write(int) method in Java with Examples K Kirti_Mangal Follow Improve Article Tags : Java Java-Functions Java-IO package Java-PrintStream Practice Tags : Java Similar Reads PrintStream write(int) method in Java with Examples The write(int) method of PrintStream Class in Java is used to write the specified byte value on the stream. This byte value is specified using the ASCII value of the byte value passed as an integer value. This integer value is taken as a parameter. Syntax: public void write(int ascii) Parameters: Th 2 min read PrintStream write(int) method in Java with Examples The write(int) method of PrintStream Class in Java is used to write the specified byte value on the stream. This byte value is specified using the ASCII value of the byte value passed as an integer value. This integer value is taken as a parameter. Syntax: public void write(int ascii) Parameters: Th 2 min read PrintWriter write(char[], int, int) method in Java with Examples The write(char[], int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified character array on the stream. This character array is taken as a parameter. The starting index and length of characters to be written are also taken as parameters. Syntax: public vo 2 min read PrintWriter write(char[], int, int) method in Java with Examples The write(char[], int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified character array on the stream. This character array is taken as a parameter. The starting index and length of characters to be written are also taken as parameters. Syntax: public vo 2 min read PrintWriter write(String, int, int) method in Java with Examples The write(String, int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified String on the stream. This String is taken as a parameter. The starting index and length of String to be written are also taken as parameters. Syntax: public void write(String string 2 min read PrintWriter write(String, int, int) method in Java with Examples The write(String, int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified String on the stream. This String is taken as a parameter. The starting index and length of String to be written are also taken as parameters. Syntax: public void write(String string 2 min read Like