Probably converting a stream or file to String is one of the most common question asked when one starts using Java. Out of different solutions, the common one is to use BufferedReader .

Recently I stumbled upon a java weblog, which suggested following one liner cool trick :

// e.g String fileString = new Scanner(this.getClass().  
                 //getResourceAsStream(fileName)).useDelimiter("\\Z").next();  
String text = new Scanner( source ).useDelimiter("\\Z").next();