Estou tentando gerar um arquivo CSV, estou conseguindo escrever mas preciso separa por colunas. Gostaria de saber como.
public void tratarArquivo(String pathArquivo) {
String caminhoOld = pathArquivo;
Path pathOld = Paths.get(caminhoOld);
List<String> linhas = null;
FileWriter fw = null;
BufferedWriter bw = null;
File newFile = new File("C:\\Users\\wesley.costa\\AppData\\Local\\Temp\\Pedidos3PNew.csv");
try {
System.out.println(newFile.exists());
if(!newFile.exists()){
newFile.createNewFile();
}else {
newFile.delete();
newFile.createNewFile();
}
fw = new FileWriter(caminhoNew);
bw = new BufferedWriter(fw);
linhas = Files.readAllLines(pathOld, StandardCharsets.ISO_8859_1);
} catch (Exception e) {
e.printStackTrace();
}
try {
for(String l : linhas){
String[] colunas = l.split(";");
for(String c : colunas){
bw.write(c.replace("\"", ""));
}
bw.newLine();
}
//\t
//Codigo tabulação
bw.close();
fw.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}