Possible Duplicate: How to create a Java String from the contents of a file Whole text file to a String in Java
If the file is small, you can read the whole data once:
File file = new File("a.txt"); FileInputStream fis = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; fis.read(data); fis.close(); String str = new String(data, "UTF-8");