import java.io.*; import java.util.*; class FileDemo { public static void main(String args[]) throws IOException { System.out.print("Please Enter name of the file:"); Scanner newFile=new Scanner(System.in); String fileName=newFile.next(); Scanner s=new Scanner(System.in); String employeeName, employeeAddress, phoneNumber; int ch1 = '0'; try { BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); do { System.out.print("Please enter your name: "); employeeName=s.next(); out.write(employeeName+"\t"); System.out.print("Please enter address:"); employeeAddress=s.next(); out.write(employeeAddress+"\t"); System.out.print("Please enter Telephone Number:"); phoneNumber=s.next(); out.write(phoneNumber); out.newLine(); System.out.println("Press Ctrl-z to terminate"); } while( (ch1 = System.in.read() ) != -1); out.close(); }catch(IOException e) { System.err.println ("Error writing to file"); } BufferedReader in=new BufferedReader(new FileReader(fileName)); while(true) { if (! in.ready()) break; String next_line = in.readLine(); System.out.println("\n"+next_line); } } }