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();
}
}