0
什麼是自動化獲取CSV文件,將文件的某些內容編輯/複製到另一個CSV文件的過程的最佳方式?自動化一個過程,將CSV的某些部分複製到一個新的CSV文件中
理想情況下,有一個文件夾需要以相同的方式修改1000個CSV。因此自動化。有什麼建議麼?
什麼是自動化獲取CSV文件,將文件的某些內容編輯/複製到另一個CSV文件的過程的最佳方式?自動化一個過程,將CSV的某些部分複製到一個新的CSV文件中
理想情況下,有一個文件夾需要以相同的方式修改1000個CSV。因此自動化。有什麼建議麼?
只需讀取csv文件字段並更改/編輯並將所有字段保存到另一個csv文件。
舉例來說,如果我有一個CSV文件(user.csv)和該文件包含2列username
和password
,我想更新的領域,編碼是在這裏:
String text = null;
string filename="user.csv";
try {
FileInputStream fis = new FileInputStream(filename);
DataInputStream myInput = new DataInputStream(fis);
while ((text = myInput.readLine()) != null) {
// System.out.println(text);
String[] strar = text.split(",");
String username = strar[0];
String password = strar[1];
// so here you can update both username and password and save into another
csv file
string write=username +","+password ;
WriteToCsv(write);
}
} catch (IOException ex) {
ex.printStackTrace();
enter code here
//save into csv file here
public static synchronized void WriteToCsv(String s) {
PrintWriter pw = null;
try {
File f = new File(newfile);
pw = new PrintWriter(new FileWriter(f, true));
pw.println(s);
pw.flush();
pw.close();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
pw.close();
}
}