`

[Java]How to use Common CSV

    博客分类:
  • Java
csv 
阅读更多

参考:https://www.callicoder.com/java-read-write-csv-file-apache-commons-csv/

 

生成

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;

public class CSVWriter {
    private static final String SAMPLE_CSV_FILE = "./sample.csv";

    public static void main(String[] args) throws IOException {
        try (
            BufferedWriter writer = Files.newBufferedWriter(Paths.get(SAMPLE_CSV_FILE));

            CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT
                    .withHeader("ID", "Name", "Designation", "Company"));
        ) {
            csvPrinter.printRecord("1", "Sundar Pichai ♥", "CEO", "Google");
            csvPrinter.printRecord("2", "Satya Nadella", "CEO", "Microsoft");
            csvPrinter.printRecord("3", "Tim cook", "CEO", "Apple");

            csvPrinter.printRecord(Arrays.asList("4", "Mark Zuckerberg", "CEO", "Facebook"));

            csvPrinter.flush();            
        }
    }
}

 

分享到:
评论

相关推荐

    Foundations for Analytics with Python O-Reilly-2016-Clinton W. Brownley

    Next, the chapter discusses how to use three different types of conditional logic to filter for specific rows from the input file and write them to a CSV output file. Then the chapter presents two ...

    UE(官方下载)

    How to check your JavaScript source code for common mistakes without actually running the script or opening the web page Character properties at your fingertips Access the properties of a character ...

    Apache Spark 2.x for Java Developers

    Use the Spark Java API to implement efficient enterprise-grade applications for data processing and analytics Go beyond mainstream data processing by adding querying capability, Machine Learning, and ...

    Go CookBook golang

    how to make use of them. The Go standard library frequently uses these interfaces, and these interfaces will be used by recipes throughout the book. You'll learn how to work with data in ...

    Kotlin Blueprints-Packt Publishing(2017).epub

    With Google officially recognizing Kotlin's use to develop Android apps, this is the most widespread application to use the Kotlin language. Today's mobile apps hardly work in isolation. They work ...

    Active Directory Cookbook, 3rd Edition.pdf

    Covers basic schema administration tasks, such as generating object identifiers (OIDs) and schemaIDGUIDs, how to use LDIF to extend the schema, and how to locate attributes or classes that match ...

    Wireshark- A Guide to Color My Packets

    This guide aims to provide a detailed overview of how to use Wireshark effectively, specifically focusing on the creation of display filters and coloring rules for easier identification of network ...

    Pro Python 2nd edition 英文pdf

    This book is for intermediate to advanced Python programmers who are looking to understand how and why Python works the way it does and how they can take their code to the next level. Table of ...

    Udemy - Deep Learning Recurrent Neural Networks in Python

    This course focuses on “how to build and understand“, not just “how to use”. Anyone can learn to use an API in 15 minutes after reading some documentation. It’s not about “remembering facts”, ...

    impala-2.8

    - **Load CSV Data from Local Files**: Understand how to import data from CSV files into Impala. - **Point an Impala Table at Existing Data Files**: Explore how to link Impala tables to data stored ...

    Get Programming with F#

    Use minimal code to work with JSON, CSV, XML, and HTML data Integrate F# with your existing C# and VB.NET applications Create web-enabled applications about the reader Written for intermediate C# and...

    BSD Hacks.pdf

    This hack explains how to create and use these bindings to streamline common tasks and speed up workflows. 4. **Using Terminal and X Bindings (HACK 4):** This section focuses on terminal and X ...

    R for beginner

    To save data created within R, you can use the `write.table()` or `write.csv()` functions. For example: ```r write.csv(data, "saved_data.csv", row.names = FALSE) ``` ##### Generating Data R provides ...

    Spark_for_Python

    This section covers the basics of PySpark, including how to create and manipulate Resilient Distributed Datasets (RDDs), DataFrames, and Datasets. **3. Setting Up the Development Environment** The ...

    用友自动化测试面试题

    - **Languages Used**: Common languages used include Java, Python, C#, and JavaScript. - **Projects**: Involved in developing test scripts, automation frameworks, and integration testing. #### 10. ...

    Python for Bioinformatics 第二版,最新版

    1.5.3 How Is It Used? 14 1.5.4 Who Uses Python? 15 1.5.5 Flavors of Python 15 1.5.6 Special Python Distributions 16 1.6 ADDITIONAL RESOURCES 17 Chapter 2 First Steps with Python 19 2.1 INSTALLING ...

    python3.6.5参考手册 chm

    Common Stumbling Blocks Print Is A Function Views And Iterators Instead Of Lists Ordering Comparisons Integers Text Vs. Data Instead Of Unicode Vs. 8-bit Overview Of Syntax Changes New Syntax ...

    ZendFramework中文文档

    9.4.3. Basic Zend_Date Operations Common to Many Date Parts 9.4.3.1. List of Date Parts 9.4.3.2. List of Date Operations 9.4.4. Comparing Dates 9.4.5. Getting Dates and Date Parts 9.4.6. Working ...

    arcgis工具

    最好把EXCEL保存为.csv文件去除一些不兼容的内容再连接。 转载ESRI论坛Lucy1114帖子说明: 12. 导出Shape格式为其他软件识别的打印格式如JEPG等格式 FILE/EXPORT MAP 然后选择相应的图片格式,此时也可设置答应...

Global site tag (gtag.js) - Google Analytics