This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: How to read file in Java using Scanner Example - text files
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
From Java 5 onwards java.util.Scanner class can be used to read
file in Java. Earlier we have seen example of reading
file in Java using FileInputStream and reading
file line by line using BufferedInputStream and in this Java tutorial we
will See How can we use Scanner to read files in Java. Scanner is a
utility class in java.util package and provides several
convenient method to read int, long, String, double etc from
source which can be an InputStream,
a file or a String itself. As noted on How
to get input from User, Scanner is also an easy way to read
user input using System.in (InputStream) as source.Main advantage of using Scanner for reading file is that it allows you to change delimiter using useDelimiter() method, So you can use any other delimiter like comma, pipe instead of white space.