Final Code: TO run this code, clone it and open it with Netbeans IDE.On the IDE right click on the project and select Set Configuration.then click customize and on the arguments field add data.txt
Final working version