Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java Examples - Write to a file


previous next AddThis Social Bookmark Button


Problem Description:

How to write into a file ?

Solution:

This example shows how to write to a file using write method of BufferedWriter.

import java.io.*;

public class Main {
   public static void main(String[] args)  {
      try {
         BufferedWriter out = new 
         BufferedWriter(new FileWriter("outfilename"));
         out.write("aString");
         out.close();
         System.out.println
         ("File created successfully");
      }
      catch (IOException e) {
      }
   }
}

Result:

The above code sample will produce the following result.

File created successfully.


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names