tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > IO > Write Text File

Write Text File 

The following example shows how to write into a text file using BufferedWriter. The newLine() method outputs a newline to the character stream.

File Name  :  
com/bethecoder/tutorials/io/WriteTextFile.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.io;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class WriteTextFile {

  /**
   @param args
   */
  public static void main(String[] args) {

    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\abc.txt"));
      writer.write("Hello World ");
      writer.newLine();
      writer.write("WriteTextFile Example");
      writer.close();
      System.out.println("Successfully written to file");
    catch (IOException e) {
      e.printStackTrace();
    }
  }

}
   

It gives the following output,
Successfully written to file


                    Print

   



Books Recommendation

 
 
bl  br