我將兩個csv文件與不同的標題組合在一起。我遇到了將值寫入新csv的問題。任何人都可以幫忙。寫入CSV文件
將csv文件中的值合併並在控制檯中打印。我需要將這些值寫入新的csv文件。
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class MainCSV {
public static void main(String[] args){
MainCSV obj = new MainCSV();
obj.run();
}
public void run() {
String csvFile = "E:/CSV/6d54979e-60da-4c73-b6e5-b2138a7450ca.csv";
String csvFile2 = "E:/CSV/9b5659f2-38e8-4bbd-bd7c-74ad683d5c59.csv";
BufferedReader br = null;
BufferedReader br2 = null;
String line = "";
String line2 = "";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br2 = new BufferedReader(new FileReader(csvFile2));
System.out.println("--------------------------------------------------------");
while ((line2 = br2.readLine()) != null) {
System.out.println(line2);
StringBuffer strbuf;
strbuf = new StringBuffer(line2);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println("Done");
}
}