FileWriter Class

How to use Java FileWriter Class

FileWriter is the character representation of . That means it can be used to write characters. It extends OutputStreamWriter , which is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset.

Character Encoding

This Class assumes that you want to decode the bytes in the file using the default character encoding for the program is running on. This may not always be what you want, and you cannot change it. So, if you want to specify a different character decoding scheme, try to avoid this class. OutputStreamWriter is the better option. The OutputStreamWriter lets you specify the character encoding scheme to use when writing bytes to the underlying file.


Java FileWriter with append mode

When you create file using Java FileWriter Class you can decide whether you want to overwrite existing file with the same name or if you want to append to any existing file. You decide that by choosing what FileWriter constructor you use. When pass true as a second argument to FileWriter to turn on "append" mode.

In the above code, all existing content will be overridden.

Above code keep the existing content and append the new content to the end of a file.

 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About