Code

Java Util Scanner – Read File Into String

One line trick to read the contents of a file into a string…

<pre>String text = new Scanner( new File("poem.txt") ).useDelimiter("\\A").next();

Reference Blog:
https://blogs.java.net/blog/pat/archive/2004/10/stupid_scanner.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s