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 :



String text = new Scanner( source ).useDelimiter("\\Z").next();