Skip to content

Instantly share code, notes, and snippets.

@xhiroga
Last active December 4, 2017 14:36
Show Gist options
  • Save xhiroga/6f1be71972a28c59d355a71d2e005fc7 to your computer and use it in GitHub Desktop.
Save xhiroga/6f1be71972a28c59d355a71d2e005fc7 to your computer and use it in GitHub Desktop.
Csvの中身を読み取って書き出すシンプルなプログラム。練習用だよ。
import java.io.*;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.csv.CSVFormat;
public class Csv{
public static void main(String[] args){
try{
String homeDir = System.getenv("HOME");
Reader reader = new FileReader(homeDir + "/dev/lrn/java/file/read.csv");
FileWriter writer = new FileWriter(homeDir + "/dev/lrn/java/file/write.csv");
Iterable<CSVRecord> records = CSVFormat.RFC4180.withHeader().parse(reader);
for(CSVRecord rc : records){
writer.write(rc.get("Name"));
}
reader.close();
writer.flush();
writer.close();
}catch(IOException e){
System.out.println(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment