Java read CSV File 📰

IMPORTANT NOTE: If values in your CSV contain commas naturally, they will be split. (Ex. $1,000). If this is the case, replace: String[] row = line.split(",...

Bro Code•110.6K views•9:12

About this video

IMPORTANT NOTE: If values in your CSV contain commas naturally, they will be split. (Ex. $1,000). If this is the case, replace: String[] row = line.split(","); with String[] row = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)"); ^ This is regex and is very complicated. It looks for string patterns. Explaining this requires another video entirely. //****************************************************** import java.io.*; public class Main { public static void main(String[] args) { //CSV = Comma-Separated Values // text file that uses a comma to separate values String file = "src\\students.csv"; BufferedReader reader = null; String line = ""; try { reader = new BufferedReader(new FileReader(file)); while((line = reader.readLine()) != null) { String[] row = line.split(","); //String[] row = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)"); //use this if your values already contain commas for(String index : row) { System.out.printf("%-10s", index); } System.out.println(); } } catch(Exception e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } //******************************************************

Tags and Topics

This video is tagged with the following topics. Click any tag to explore more related content and discover similar videos:

Tags help categorize content and make it easier to find related videos. Browse our collection to discover more content in these categories.

4.7

22 user reviews

Write a Review

0/1000 characters

User Reviews

0 reviews

Be the first to comment...

Video Information

Views
110.6K

Total views since publication

Likes
2.6K

User likes and reactions

Duration
9:12

Video length

Published
Jul 6, 2020

Release date

Quality
hd

Video definition

Captions
Available

Subtitles enabled

Related Trending Topics

LIVE TRENDS

This video may be related to current global trending topics. Click any trend to explore more videos about what's hot right now!

THIS VIDEO IS TRENDING!

This video is currently trending in South Korea under the topic 'a'.

Share This Video

SOCIAL SHARE

Share this video with your friends and followers across all major social platforms including X (Twitter), Facebook, Youtube, Pinterest, VKontakte, and Odnoklassniki. Help spread the word about great content!