Last active
December 4, 2017 14:36
-
-
Save xhiroga/6f1be71972a28c59d355a71d2e005fc7 to your computer and use it in GitHub Desktop.
Csvの中身を読み取って書き出すシンプルなプログラム。練習用だよ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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