I am new to java programming and looking for options to write and append file content with java.
Similar options for below C# options.
File.WriteAllText(string path, string contents, Encoding encoding);
File.AppendAllText(string path, string contents, Encoding encoding);
I though to use BufferedWriter, it have option to pass true/false for FileWriter(String path, boolean append) but i don't have option to provide Encoding.
try (FileWriter fw = new FileWriter(path, false);
BufferedWriter bw = new BufferedWriter(fw)) {
bw.write("appending text into file");
}
If I initialize BufferedWriter with Files.newBufferedWriter, I can provide StandardCharsets, but it don't have option to append in case of existing file.
try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(path), StandardCharsets.UTF_8)) {
bw.write("test");
bw.append("append test");
}
Is it possible to define both option together (Append options and StandardCharsets)?