Write in Text File in Java Program

  1. import java.io.*;  
  2.   
  3. public class WriteTextFileExample{  
  4.     public static void main(String[] args)throws IOException{  
  5.         Writer output = null;  
  6.         String text = "Rajesh Kumar";  
  7.         File file = new File("write.txt");  
  8.         output = new BufferedWriter(new FileWriter(file));  
  9.         output.write(text);  
  10.         output.close();  
  11.         System.out.println("Your file has been written");          
  12.     }  
  13. }  
  14.