Program to convert Byte Array to Writer in Java Last Updated : 11 Dec, 2018 Comments Improve Suggest changes Like Article Like Report References: Writer Class Approach: Writer class is used to write character stream, by which byte array can be passed as an argument. By this way, byte array can be converted into Writer class. To get the byte array from String, getBytes() method is used. Below is the implementation of the above approach: Program: Java // Java Program Convert // Byte Array to Writer import java.io.StringWriter; import java.io.Writer; public class GFG { // Method which convert // byte array into Writer Class static String writeByte(byte[] byteString, byte[] byteInt, byte[] byteChar, byte[] byteDouble) { // Declare the writer class Writer writer = new StringWriter(); try { // Call append() method // to append byte array into // writer class as append method // takes input of only string object writer .append(new String(byteString) + new String(byteDouble) + new String(byteChar) + new String(byteInt)); writer.close(); } catch (Exception e) { System.out.println("Exception: " + e); } // return the string return writer.toString(); } // Driver Code public static void main(String args[]) { String str = "Speed of light: "; int num = 8; char ch = 'e'; double dec = 3.0; // Insert String value byte[] byteString = str.getBytes(); // Insert int value byte[] byteInt = Integer.toString(num).getBytes(); // Insert char value byte[] byteChar = Character.toString(ch).getBytes(); // Insert double value byte[] byteDouble = Double.toString(dec).getBytes(); // Call the method System.out.println(writeByte(byteString, byteInt, byteChar, byteDouble)); } } Output: Speed of light: 3.0e8 Comment More infoAdvertise with us Next Article Program to convert Byte Array to Writer in Java B bilal-hungund Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2018 Java-Arrays Java-Byte Java-Array-Programs +2 More Practice Tags : Java Similar Reads Convert byte[] array to File using Java As we know whenever it comes to writing over a file, write() method of the File class comes into play but here we can not use it in order to convert that byte into a file. In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementatio 3 min read How to Write JSON Array to CSV File using Java? We will see how to read a JSONArray from a JSON file and write the contents to a CSV file using Java. JavaScript Object Notation (JSON) is a standard text-based format for representing structured data that is based on JavaScript object syntax. It is commonly used for transmitting data in web applica 3 min read ByteBuffer array() method in Java with Examples The array() method of java.nio.ByteBuffer class is used to return the byte array that backs the taken buffer.Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa.Invoke the hasArray() method before invoking this method in order to ensure that 3 min read CharArrayWriter write() method in Java with Examples The write() method of CharArrayWriter class in Java is of three types: The write(int) method of CharArrayWriter class in Java is used to write a character to the writer in form of an integer. This write() method writes one character at a time to the CharArrayWriter.Syntax: public void write(int c) O 3 min read CharArrayWriter writeTo() method in Java with Examples The writeTo(Writer) method of CharArrayWriter class in Java is used to write the contents of the CharArrayWriter to another character stream.Syntax: public void writeTo(Writer out) throws IOException Parameters: This method accepts one parameter out that represents the output stream that is the dest 1 min read Like