Lesson 11 - File IO
Lesson 11 - File IO
File I/O
The File class from the java.io package, allows us to work with files. To use the File class, create
an object of the class, and specify the filename or directory name:
import java.io.File; // Import the File class
File myObj = new File("filename.txt");
✓ Here “filename.txt” is the file that will be created.
✓ This file will be created in the folder where you have kept the rest of the code.
Reading from file: We create object of FileReader class to read some text from a file we created.
We create BufferedReader object using the FileReader class object to read the file content. Note
that when you are done reading to the file, you should close it with the close() method.