Skip Navigation Links



How to read file line by line in Java - BufferedReader Scanner Example Tutorial

Author : Javin Paul      Blog :TIBCO RV FIX PROTOCOL JAVA TUTORIAL      Date: 7/23/2012 3:10:00 PM


Line by Line reading in Java using BufferedReader and Scanner
There are multiple ways to read file line by line in Java. Most simple example of reading file line by line is using BufferedReader which provides method readLine() for reading file. Apart from generics, enum and varargs Java 1.5  has also introduced several new class in Java API one of the  utility class is Scanner, which can also be used to read any file line by line in Java. Though BufferedReader is available in Java from JDK 1.1,  java.util.Scanner provides more utility methods compared to BufferedReader. Scanner has method like hasNextLine() and nextLine() to facilitate line by line reading of file's contents. nextLine() returns String similar to  readLine() but scanner has more utility methods like nextInt(), nextLong() which can be used to directly read numbers from file instead of converting String to Integer or other Number classes. By the way Scanner is rather new approach for reading file and BufferedReader is the standard one. This is my 6th tutorial on Java IO,  In last couple of post we have seen creating file and directory in Java, parsing XML files using DOM and how to read properties file in Java. In this post we will focus on reading file line by line in Java using both BufferedReader and Scanner.
Read more »

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(71)

AMJAD KHAN(5)

Vashi Chandiramani(5)

Ambica Srimal(2)

Ankit Gupta(2)

BUTTERFLIES OF TIME(2)

churumuri(2)

deponti(2)

DIGITALASIAN(2)

Firoze Shakir Photographerno1(2)

Harimohan(2)

ravi dabas(2)

RWABhagidari.blogspot.com(2)

Sam Hindus Blog.(2)

Vidya Sury(2)

Aarthi(1)

Abhishek K. Mishra(1)

aburman(1)

Ajithkumar Krishnakumar(1)

aKuma(1)

Anand VijayaKumar(1)

Anita Jeyan Sandeep(1)

ankush samant(1)

Anu Varma(1)

Artnavy(1)

ashwin35007(1)

Ashwini Kumar(1)

Aurindam Mukherjee(1)

Beyond(1)

churumuri(1)

Cynical(1)

Debolina Raja Gupta(1)

Debolina Raja Gupta(1)

delhizen(1)

Disha(1)

Elizabeth(1)

Farida Rizwan(1)

Fidarose Isha(1)

Fire Crystals(1)

Gayu(1)

Govind Kumar(1)

Hawk Eye(1)

Hemant Sonawanes Studio(1)

Ibrahim(1)

Indian Thematic Society(1)

Indrani(1)

Iti(1)

Izaj Ahmed Shaikh(1)

Jaya(1)

jayanpsk(1)

Jhoomur Bose(1)

Jishnu Saji(1)

Jnanaswarupan ji(1)

jquerybyexample(1)

Kalyani(1)

Kannada Cuisine(1)

Krishna Rao(1)

Lluvia....(1)

Madhavi Madhurakavi(1)

Maliny(1)

Mandira(1)

Manreet Sodhi Someshwar(1)

Megha Sarin(1)

mêlée(1)

Miles Of Style(1)

Minu CP(1)

Miss Frangipani(1)

Modern Gypsy(1)

Monu Awalla(1)

Mosarrap H Khan(1)

Mythreyi(1)

Nanka(1)

Nidz(1)

nimisha mistry(1)

Nisha(1)

palak sharma(1)

Pari Vasisht(1)

Pooja Lokhande(1)

Prahallad Panda(1)

pratish(1)

R.D. Bhalekar(1)

Raksha(1)

Rani Acharyulu(1)

Ranjith(1)

Renu(1)

Ritesh Agarwal(1)

RNA Corp(1)

sahiljshah21(1)

sanarao(1)

sangeeta(1)

SEO(1)

Shazia M(1)

Shobha(1)

Shruthi(1)

Shyam Bhatawdekar(1)

sidhu352(1)

Simran(1)

smile khan(1)

Sneha (1)

soraya nulliah(1)

Srivalli(1)

Suchithra(1)

Sue(1)

Sujoy Das(1)

suraj savardekar(1)

Swapna(1)

The Parenting Forum(1)

Thommy(1)

vandysnape(1)

verbivorehere(1)

Vikram Karve(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com