`

[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 ...

    Apache Solr 3 Enterprise Search Server

    Design a schema to include text indexing details like tokenization, stemming, and synonyms Import data using various ...Scale Solr by learning how to tune it and how to use replication and sharding

    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 ...

    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 ...

    Mastering.Jira.7.2nd.Ed

    It shows you how to master the key functionalities of JIRA and its customizations and useful add-ons, and is packed with real-world examples and use cases. You will first learn how to plan for a ...

    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”, ...

    Packtpub.Python.2.6.Text.Processing.Beginners.Guide.Dec.2010

    Python 2.6 Text Processing Beginner’s Guide is the easiest way to learn how to manipulate text with Python. Packed with examples, it will teach you text processing techniques and give you the skills ...

    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...

    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 然后选择相应的图片格式,此时也可设置答应...

    Sql for mysql

    CHAPTER 5 SELECT Statement: Common Elements . . . . . . . . . . . . 73 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 5.2 Literals and Their Data ...

Global site tag (gtag.js) - Google Analytics