Read a File into a String using a single statement
Writing by shivdev on Monday, 18 of November , 2013 at 6:08 am
I’ve found that java.util.Scanner class instead of the java.io classes to work well for most of my text file reading and parsing needs.
String content = new Scanner(new File("/path/to/file.txt")).useDelimiter("\\Z").next(); System.out.println(content);
For more info read up natch3z or coderwall.
Leave a comment
Category: Java
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-
No Comments
No comments yet.
Leave a comment
You must be logged in to post a comment.