【发布时间】:2017-02-20 05:59:07
【问题描述】:
我正在编写一个程序来从一个 csv 中选择几列并将其写入另一个 csv。 我可以选择要写入的列,但无法将其写入另一个 csv。
公共类 ReadingCSV {
public static void main(String[] args) {
String csvFile = "/Users/Desktop/NEW Automation/combined.csv";
String out = "/Users/Desktop/NEW Automation/a.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] mydata = line.split(cvsSplitBy);
//System.out.println("[Client = " + mydata[1] + " , Acct_id=" + mydata[2] + "]");
PrintWriter output = new PrintWriter("out", "UTF-8");
output.println(mydata[0] + cvsSplitBy + mydata[1] + cvsSplitBy + mydata[2]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
【问题讨论】:
标签: java