2
I have a file .txt
with three names separated by comma, in this case:
test.txt
João,Maria,José
In my class I take the file and pass 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 pick up some positions from array
and save in another .txt
that would be the gerado.txt
(emptiness).
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?