Convert Stream or File to String in Java
Written by Aminur Rashid   
Friday, 26 April 2013


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("\\A").next();
String text = new Scanner( source ).useDelimiter("\\A").next();







StumbleUponDigg This!Bookmark on Delicious

Add as favourites (423) | Quote this article on your site | Views: 1675 | E-mail

Be first to comment this article
RSS comments

Only registered users can write comments.
Please login or register.

Last Updated ( Friday, 26 April 2013 )