Tuesday , January 23 2018
Home / JAVA / Convert Writer to String in Java

Convert Writer to String in Java

Here is the Java Program for Writer to String Conversion : If you want to convert writer to string java here is the example for StringWriter Stream that is to be imported from the package Java.io. Here we are using append function.


  • package com.getprogramcode.string;
    import java.io.StringWriter;
    public class WriterToString {
        public static void main(String args[]){
            // create an instance of writer class and store it to a variable
              StringWriter var = new StringWriter();
              // appending string-characters        
              var.append("Welcome to ");
              String temp = var.toString();
              System.out.println(temp);     // thus a writer is converted to string using java program
  • You can also create an instance of StringWriter Class and allocate it to an object of parent class Writer

    Writer writer = new StringWriter(); //
    String data = writer.toString(); 

    Rest will remain the same. Just the object creation and initialization can be different You can also make it using other functions like:


Welcome to Getprogramcode.com

Also See:   How to Null a string or empty a string array

Check Also

C Program to restrict Mouse pointer in a Rectangle

This C Program will restrict the Mouse pointer Position in the Rectangle. The Mouse Programs are listed here ...

Leave a Reply

Your email address will not be published. Required fields are marked *