Created
February 22, 2015 18:21
-
-
Save pgtwitter/c03c2572742c4931c41e to your computer and use it in GitHub Desktop.
任意のカラムだけ抜き出したCSVファイルのバイト列を作る (OpenCSVを用いた)
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 au.com.bytecode.opencsv.CSVReader; | |
//import au.com.bytecode.opencsv.CSVWriter; | |
String encoding= "UTF-8"; | |
Reader in = new InputStreamReader(new FileInputStream("/path/to/csvfile.csv"), encoding); | |
ByteArrayOutputStream ret = new ByteArrayOutputStream(); | |
Writer out = new OutputStreamWriter(ret, encoding); | |
CSVWriter writer = new CSVWriter(out, ',', '"', '"', "\n"); | |
CSVReader reader = new CSVReader(in); | |
String[] e; | |
while ((e = reader.readNext()) != null) { | |
writer.writeNext(new String[] { | |
e[0] | |
}); | |
} | |
reader.close(); | |
writer.close(); | |
byte[] buf= ret.toByteArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment