CSV File Reading Example
This program demonstrates reading CSV files.
Problem Statement
Write a Java program that reads a CSV file and prints its contents.
Source Code
| 1 | import java.io.*; |
| 2 | public class ReadCSVExample { |
| 3 | public static void main(String[] args) { |
| 4 | System.out.println("Eduinq Read CSV Example"); |
| 5 | try(BufferedReader br=new BufferedReader(new FileReader("data.csv"))) { |
| 6 | String line; |
| 7 | while((line=br.readLine())!=null){ |
| 8 | String[] values=line.split(","); |
| 9 | System.out.println("Eduinq Row: "+String.join(" | ",values)); |
| 10 | } |
| 11 | } catch(IOException e) { |
| 12 | System.out.println("Eduinq Exception: "+e.getMessage()); |
| 13 | } |
| 14 | } |
| 15 | } |
Program Output
Eduinq Read CSV Example Eduinq Row: 1 | Arun | India Eduinq Row: 2 | Priya | USA
Explanation
CSV reading uses BufferedReader and split() for parsing. - Each line is split into values by commas. - Exception handling ensures safe operations. - In enterprise systems, CSV reading is used for importing structured data. Conclusion: Shows reading CSV files.