Posts

Showing posts from August, 2020

Reading Data from a CSV file

Reading data from a CSV File: Before Starting to Understand how to read data from a CSV file let us understand the basics of how to read data from a file. The classes that we need are BufferedReader and FileReader class: https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html https://docs.oracle.com/javase/7/docs/api/java/io/FileReader.html 1. FileReader Class: The file reader class is used to read a file as a stream of chars. The FileReader Class extends the Reader Class. If you want to read a file as a stream of bytes you can use InputStream but reading as stream of bytes is very slow.  File reader reads data from a file as a stream of characters, i.e one character at a time which can be of any byte size The  Java   BufferedReader  class,  java.io.BufferedReader , provides buffering for your Java  Reader  instances. Buffering can speed up IO quite a bit. Rather than read one character at a time from the underlying  Reader , the Java  BufferedReader  reads a larger block