The BufferReader filter class can be used to read text ( string of characters) from a file or can be used to capture keyboard inputs.
  • FileReader fr = new FileReader(file_name); //this gets the file name
    BufferedReader br = new BufferedReader(fr);// the contents are stored in a buffer
    String line= "";
    System.out.println("Reading from " + file_name);
    while ((line = br.readLine())!= null) // this loop reads the character streams till it is null.
It is also worth of looking how to write and read an object using ObjectOutputStream(xyz)Link

package ch4_package;
import java.io.*;
public class Test_This {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String file_name ="", str_text="";
Process pp = new Process();
try{
//System.out.println("---While Loop---");
System.out.print("Please Enter a File name: ");
file_name = br.readLine();
System.out.print("Now the text to be added : ");
str_text = br.readLine();
pp.process(file_name, str_text);
}//try
catch(NumberFormatException e)
{ System.out.println("data was blank");}
}
}
class Process {
public String file_name="";
File create_file;
String show_text= "";

public void process(String str1, String str2)
{
try {
File file = new File(str1);
boolean success = file.createNewFile();
if (success){
file_name= file.getName();
show_text = str2;
System.out.println( "file name " + file_name);
System.out.println("Writing to this file");
char buff[] = new char[show_text.length()];
show_text.getChars(0,show_text.length(),buff, 0);
FileWriter fr = new FileWriter(str1);
for (int i =0; i <buff.length; i++)
{
fr.write(buff[i]);
}
fr.close();
read_file();
}
} catch (IOException e) { System.out.println("could not read");
}


}

public void read_file()
{
try {
FileReader fr = new FileReader(file_name);
BufferedReader br = new BufferedReader(fr);
String line= "";
System.out.println("Reading from " + file_name);
while ((line = br.readLine())!= null)
{
System.out.println(line);
}
fr.close();
} catch (IOException e) { System.out.println("could not read");
}
}
}