Files Class readString() Method in Java with Examples Last Updated : 27 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 readString() method. public static String readString​(Path path) throws IOException public static String readString​(Path path, Charset cs) throws IOExceptionUsing the UTF-8 charset in the first method reads all content from a file into a string, decoding from bytes to characters.The second method does the same using the specified charset. Input File: Input File Below is the implementation of the problem statement: Java // Implementation for readString() method in Java import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) { // creating path Path filePath = Paths.get("/home/mayur/", "temp", "gfg.txt"); try { // reading file from given path String content = Files.readString(filePath); // printing the content System.out.println(content); } catch (IOException e) { e.printStackTrace(); } } } Output: Hello from GFG! Comment More infoAdvertise with us Next Article Convert String to Stream of Chars in Java K KapilChhipa Follow Improve Article Tags : Java Java Programs Java-File Class Practice Tags : Java Similar Reads Files Class writeString() Method in Java with Examples 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 op 2 min read Loading Resources from Classpath in Java with Example Resources are the collections of files or images or stuff of other formats. Java programs help us to load these files or images of the resources and perform a read and write operation on them. For example, we can load a file from any resource directory and will be then able to read the content of th 4 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 Read a File to String There are multiple ways of writing and reading a text file. This is required while dealing with many applications. There are several ways to read a plain text file in Java e.g. you can use FileReader, BufferedReader or Scanner to read a text file. Given a text file, the task is to read the contents 8 min read Convert String to Stream of Chars in Java The StringReader class from the java.io package in Java can be used to convert a String to a character stream. When you need to read characters from a string as though it were an input stream, the StringReader class can be helpful in creating a character stream from a string. In this article, we wil 2 min read How to Split a String in Java with Delimiter? In Java, the split() method of the String class is used to split a string into an array of substrings based on a specified delimiter. The best example of this is CSV (Comma Separated Values) files.Program to Split a String with Delimiter in JavaHere is a simple program to split a string with a comma 2 min read Like