close io streams and change String to StringBuilder to improve performance