FileWriter
Since there are classes for file reading, there must be classes for file writing. The usage is similar to that of FileReader:
FileWriter writer = new FileWriter("test.properties");
writer.write("test");
Writing to a file can be divided into two modes: append mode and overwrite mode. Append mode can be achieved using the append method, while overwrite mode can be achieved using the write method. There is also a write method with an optional second parameter for overwrite mode.
Similarly, this class provides:
- getOutputStream
- getWriter
- getPrintWriter
These methods provide more flexible ways to write to files by converting to corresponding classes.