File tree 3 files changed +29
-0
lines changed
3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
/src /TestProgram.java
2
2
/src /TestProgram2.java
3
+ /src /TestProgram3.java
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ import org .apache .commons .csv .CSVFormat ;
2
+ import org .apache .commons .csv .CSVParser ;
3
+ import org .apache .commons .csv .CSVRecord ;
4
+
5
+ import java .io .File ;
6
+ import java .io .FileInputStream ;
7
+ import java .io .InputStreamReader ;
8
+
9
+ public class JavaParseCsvFile {
10
+ public static void main (String args []){
11
+ System .out .println ("=============Java CSV Parse Example================" );
12
+
13
+ File csvFile =new File ("sample_file.csv" );
14
+
15
+ try {
16
+ InputStreamReader inputStreamReader = new InputStreamReader (new FileInputStream (csvFile ));
17
+ CSVParser csvParser = CSVFormat .DEFAULT .parse (inputStreamReader );
18
+ for (CSVRecord csvRecord :csvParser ){
19
+ System .out .println ("Column 1 : " +csvRecord .get (0 )+" | Column 2 : " +csvRecord .get (1 )+"| Column 3 : " +csvRecord .get (2 ));
20
+ }
21
+
22
+ }
23
+ catch (Exception e ){
24
+ System .out .println ("Error in Parsing CSV File" );
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments