File Reading and Writing

File Reader 

To read a text file, we need an object that can give us access to the file system. One way to do this is to make use of a BufferedReader object which streams line by line data from a text file using a FileReader object.

BufferedReader br = new BufferedReader(new FileReader("filename.txt"));

String temp = "";
while ((temp = br.readLine()) != null)

File Writer 

The file writer object is very similar but we simply make use of a BufferedWriter and FileWriter as in the example below.

BufferedWriter bw = new BufferedWriter(new FileWriter("filename.txt"));

bw.write("text to write to file");