I have a .txt
file with three comma-separated names, in this case:
test.txt
João,Maria,José
In my class I get the file and step to a array
, separating by comma:
String nomeArquivo="teste.txt";
String nomeArquivoGerado="gerado.txt";
String linha = "";
String linha2[];
try {
FileReader reader = new FileReader(nomeArquivo);
BufferedReader leitor = new BufferedReader(reader);
linha=leitor.readLine();
linha2=linha.split(",");
I want to get some positions of array
and save in another .txt
that would be gerado.txt
(empty).
FileWriter writer = new FileWriter(nomeArquivoGerado);
PrintWriter gravarArquivo = new PrintWriter(nomeArquivoGerado);
gravarArquivo.printf(linha2[0]).print(linha2[1]);
writer.close();
Can anyone tell me what I'm doing wrong?