Methods of Writer

The Writer class provides different methods that are implemented by its subclasses. Here are some of the methods:

  1. write(char[] array) - writes the characters from the specified array to the output stream.
  2. write(String data) - writes the specified string to the writer.
  3. append(char c) - inserts the specified character to the current writer.
  4. flush() - forces to write all the data present in the writer to the corresponding destination.
  5. close() - closes the writer.

Here is how we can implement the Writer using the FileWriter class.


\begin{lstlisting}
import java.io.FileWriter;
import java.io.Writer;
\par
public...
...se();
}
\par
catch( Exception e) {
e.getStackTrace();
}
}
}
\end{lstlisting}