Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-write Java writer example

Related Tutorials


 
 

Share on Google+Share on Google+

Java writer example

Advertisement
Example below demonstrates working of abstract writer class. Java writer is an abstract class build inside the java.io package. In the example several class methods of the writer class are demonstrated.

Java writer example

     

Example below demonstrates working of abstract writer class. Java writer is an abstract class build inside the java.io package.  In the example several class methods of the writer class are demonstrated.

In the example, the java writer subclasses classes, FileWriter & PrintWriter  are used to write string and other data as text characters in file rose.txt. Java writer class is used to write text files therefore as the classes of  abstract writer class is used, a character output stream forms. 

Now with the class methods, string and number type data is written in to the text files. 

Note:  While using the classes of  abstract writer class, an output stream is formed because we are flowing data as characters from the internal memory of an application to a disk file. 

Java_writer_example.java

 

 

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;

public class Java_writer_example {
  public static void main(String args[]) throws IOException {

  File file = new File("rose.txt");
  // file.createNewFile();
  FileWriter txt = new FileWriter(file);
  PrintWriter out = new PrintWriter(txt);

  out.append("Welcome to roseindia.net\n");
  char ch[] 'n''e''w''s''t''r''a''c''k''i''n',
  'd''i''a''.''c''o''m' };
  out.print("\n\tWelcome to ");
  out.write(ch);

  out.close();

  }
}

Download the code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 12, 2008

Related Tutorials

Discuss: Java writer example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
pradeep
December 26, 2011
java programming

send java programming project
DMCA.com