Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The FileWriter class

The FileWriter is used to write characters to the file.

Declaration

class FileWriter extends OutputStreamWriter

Constructors for FileWriter (CLICK HERE)

Methods inherited by FileWriter (CLICK HERE)

Example

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

 class FileWriterDemo 
 {
     public static void main(String args[]) throws IOException
     {
         FileWriter f = new FileWriter("demo.txt");
         char ch[] = {'J','A','V','A'};
         f.write(ch);
         f.write(" ");
         f.write("is very Simple");
         f.flush();
         System.out.println("File Writing Successful");
         f.close();
     }
 }

Output

File Writing Successful

The text file “demo.txt” is created in the current working dictionary.

Java Programming Language FileWriter Class in File Handling

Leave a reply