Java FileWriter Class

Java FileWriter class is used to write character-oriented data to a file. It is character-oriented class which is used for file handling in java.

Java FileWriter class declaration

public class FileWriter extends OutputStreamWriter

Constructors of FileWriter class

  1. FileWriter(String file)

    Creates a new file. It gets file name in string.

  2. FileWriter(File file)

    Creates a new file. It gets file name in File object.


Methods of FileWriter class

  1. void write(String text)

    It is used to write the string into FileWriter.

  2. void write(char c)

    It is used to write the char into FileWriter.

  3. void write(char[] c)

    It is used to check the two FilePermission objects for equality.

  4. boolean implies(Permission p)

    It is used to write char array into FileWriter.

  5. void flush()

    It is used to flushes the data of FileWriter.

Java FileWriter Example

In this example, we are writing the data in the file testout.txt using Java FileWriter class.

Flash Soon


Output:



Advertisement

Copyright ©2017 Design& develop