Home Java Java-write Java writer outputstream



Java writer outputstream
Posted on: December 12, 2008 at 12:00 AM
Following example contains subclasses of Writer & OutputStream classes. Writer & OutputStream are both abstract classes. In the example working of subclasses of both the abstract classes are demonstrated.

Java writer outputstream

     

Following example contains subclasses of  Writer & OutputStream classes. Writer & OutputStream are both abstract classes. In the example working of subclasses of both the abstract classes are demonstrated.

In the example subclass OutputStreamWriter of abstract class Writer is used. And subclasses ByteArrayOutputStream & FileOutputStream of abstract class OutputStream is used.

Writer_OutputStream.java
import java.io.*;

public class Writer_OutputStream {

  public static void main(String args[]) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputStreamWriter ow = new OutputStreamWriter(out);

  ow.write("Constructor argument is ByteArrayOutStream object");
  ow.flush();
  System.out.println(out.toString());

  FileOutputStream flt = new FileOutputStream(new File("rose.txt"));
  ow = new OutputStreamWriter(flt);
  ow.append("welcome to www.codingdiary.com");

  System.out
  .println("\nAppended sequence of characters will generate in a file rose.txt");
  ow.flush();
  }
}

Download the code

Related Tags for Java writer outputstream:
cclassclassesoutputstreamtracaisubclasswriteabstractexampleworkcontainsexamsseboteitbstrdemoputoutputstreaminsubasmntouttrclesworkingsubclassesemratexaxampwriterssubstatrackllmplfolloweaaractstrtstreamwingssrithbcstaboutputspleplonolo


More Tutorials from this section

Ask Questions?    Discuss: Java writer outputstream  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.