Files Class writeString() Method in Java with Examples Last Updated : 05 Feb, 2021 Comments Improve Suggest changes Like Article Like Report The writeString() method of File Class in Java is used to write contents to the specified file. Syntax: Files.writeString(path, string, options) Parameters: path - File path with data type as Pathstring - a specified string which will enter in the file with return type String.options - Different options to enter the string in the file. Like append the string to the file, overwrite everything in the file with the current string, etc Return Value: This method does not return any value. Below are two overloaded forms of the writeString() method. public static Path writeString(Path path, CharSequence csq, OpenOption... options) throws IOException public static Path writeString(Path path, CharSequence csq, Charset cs, OpenOption... options) throws IOException UTF-8 charset is used to write the content to file in the first method.The second method does the same using the specified charset.How the file is opened is specified in Options. Below is the implementation of the problem statement: Java // Implementation of writeString() method in Java import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class GFG { public static void main(String[] args) { // Initializing file Path with some conditions Path filePath = Paths.get("/home/mayur/", "temp", "gfg.txt"); try { // Write content to file Files.writeString(filePath, "Hello from GFG !!", StandardOpenOption.APPEND); // Verify file content String content = Files.readString(filePath); System.out.println(content); } catch (IOException e) { e.printStackTrace(); } } } Output: Hello from GFG ! !output File Comment More infoAdvertise with us Next Article Files Class writeString() Method in Java with Examples K KapilChhipa Follow Improve Article Tags : Java Java Programs Java-File Class Practice Tags : Java Similar Reads Files Class readString() Method in Java with Examples The readString() method of File Class in Java is used to read contents to the specified file. Syntax: Files.readString(filePath) Parameters: path - File path with data type as Path Return Value: This method returns the content of the file in String format. Below are two overloaded forms of the readS 1 min read Java Program to Write into a File FileWriter class in Java is used to write character-oriented data to a file as this class is character-oriented because it is used in file handling in Java. There are many ways to write into a file in Java as there are many classes and methods which can fulfill the goal as follows:Using writeString( 5 min read Writing List Contents to Text File After Deleting String in Java To write a List<String> to a text file after deleting a specific string, you can use the following steps: Iterate through the List<String> and use the remove() method to remove the desired string.Open a FileWriter and BufferedWriter to write to the text file.Iterate through the modified 3 min read How to Read and Write Files Using the New I/O (NIO.2) API in Java? In this article, we will learn how to read and write files using the new I/O (NIO) API in Java. For this first, we need to import the file from the NIO package in Java. This NIO.2 is introduced from the Java 7 version. This provides a more efficient way of handling input and output operations compar 3 min read Java Program to Write Data to Temporary File A Temporary file or a Temp file is a file that is created in order to hold information for some time while a file is being created or modified. After the successful execution of the program or after the program is closed, the temporary file is deleted. Other advantages of having a temporary file are 3 min read Like