I am writing an program to select few columns from one csv and write it into another csv. i am able to select the columns i want to write but i am not able to write it into another csv.
public class 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();
}
}
}
}
}