cara menyimpan string ke file teks

Path path = Paths.get("output.txt");
String contents = "Hello";

try {
    Files.writeString(path, contents, StandardCharsets.UTF_8);
} catch (IOException ex) {
	// Handle exception
}
Xanthous Xenomorph