In this section, you will learn how to read a file into the string.In this section, you will learn how to read a file into the string.
In this section, you will learn how to read a file into the string.
Description of code:
You can use any input stream but it is better to use FileReader class for reading the textual input. In the given example we have used BufferedReader class along with FileReader class to read data from the file using it's read() method. This data is then stored into the StringBuffer. At last, we have extracted the string from the StringBuffer and displayed it on the console.
Here is the code:
In the above code we have used FileReader and BufferedReader class to read the file into memory.