How to write into a file ?


Levels of difficulty: / perform operation:

Problem & Solution

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

JAVA Program

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) {
      }
   }
}


Output

The above code sample will produce the following result.

File created successfully.





Quantitative Aptitude
Reasoning
Programming
Interview