Monday, January 6, 2025
HomeProgrammingRead CSV File in Java

Read CSV File in Java

To read a CSV file in Java, you can use libraries like OpenCSV or Apache Commons CSV. Here’s a basic example using Java’s built-in BufferedReader:

java
import java.io.*;
public class ReadCSV {
public static void main(String[] args) throws IOException {
String file = "data.csv";
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while1 != null) {
String[] values = line.split(",");
for (String value : values) {
System.out.print(value + " ");
}
System.out.println();
}
br.close();
}
}

This code reads each line, splits it by commas, and prints the values.

  1. line = br.readLine( []
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x