Sign inSign up

ibmcom/commons-csv-ppc64le

By ibmcom

•Updated over 7 years ago

Docker image for commons-csv-ppc64le

Image
0

522

ibmcom/commons-csv-ppc64le repository overview

⁠Author

"Jay Joshi [email protected]⁠"

⁠Based On

https://github.com/apache/commons-csv⁠

⁠Usage Information

commons csv (package)

Build and run the container:

$docker build -t commonscsv .

$docker run --name demo_commonscsv -i -t commonscsv /bin/bash

To test the working of Container (try below example)

e.g.

Reading a CSV file (Access Values by Column Index)

The example below shows how you can read and parse the sample CSV file users.csv described above using Apache Commons CSV -


cd /commons-csv/target/classes

Create users.csv and BasicCSVReader.java



....Input CSV file i.e. users.csv....

Rajeev Kumar Singh ?,[email protected],+91-9999999999,India

Sachin Tendulkar,[email protected],+91-9999999998,India

Barak Obama,[email protected],+1-1111111111,United States

Donald Trump,[email protected],+1-2222222222,United States





....BasicCSVReader.java.................

import org.apache.commons.csv.CSVFormat;

import org.apache.commons.csv.CSVParser;

import org.apache.commons.csv.CSVRecord;

import java.io.IOException;

import java.io.Reader;

import java.nio.file.Files;

import java.nio.file.Paths;



public class BasicCSVReader {

    private static final String SAMPLE_CSV_FILE_PATH = "./users.csv";



    public static void main(String[] args) throws IOException {

        try (

            Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV_FILE_PATH));

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);

        ) {

            for (CSVRecord csvRecord : csvParser) {

                // Accessing Values by Column Index

                String name = csvRecord.get(0);

                String email = csvRecord.get(1);

                String phone = csvRecord.get(2);

                String country = csvRecord.get(3);



                System.out.println("Record No - " + csvRecord.getRecordNumber());

                System.out.println("---------------");

                System.out.println("Name : " + name);

                System.out.println("Email : " + email);

                System.out.println("Phone : " + phone);

                System.out.println("Country : " + country);

                System.out.println("---------------\n\n");

            }

        }

    }

}







$ javac BasicCSVReader.java

$ java BasicCSVReader





OUTPUT:



Record No - 1

---------------

Name : Rajeev Kumar Singh ?

Email : [email protected]

Phone : +91-9999999999

Country : India

---------------





Record No - 2

---------------

Name : Sachin Tendulkar

Email : [email protected]

Phone : +91-9999999998

Country : India

---------------





Record No - 3

---------------

Name : Barak Obama

Email : [email protected]

Phone : +1-1111111111

Country : United States

---------------





Record No - 4

---------------

Name : Donald Trump

Email : [email protected]

Phone : +1-2222222222

Country : United States

---------------



Additional examples are available at: https://www.callicoder.com/java-read-write-csv-file-apache-commons-csv/⁠

⁠Publication Statement

"This content is the sole responsibility of the entity that makes it available. IBM may review content to determine whether it is illegal or violates IBM policies, and IBM may remove or refuse to display content that IBM reasonably believe violates IBM policies or the law. For more information please see:

DMCA Takedown Policy: https:https://help.github.com/articles/dmca-takedown-policy⁠ IBM Takedown and DMCA Notices Website: https://www.ibm.com/legal/us/en/dmca.html⁠ IBM Copyright and Trademark Information Website: https://www.ibm.com/legal/us/en/copytrade.shtml⁠."

Please contact [email protected]⁠ ( if this content is found to be in violation of the DMCA or any related licenses or publishing conditions.

⁠Community Support

For any questions on the publication of this container, please contact us at [email protected]⁠.

Tag summary

Content type

Image

Digest

Size

485 MB

Last updated

over 7 years ago

docker pull ibmcom/commons-csv-ppc64le