[b]Estou tendo uma coleção de erros quando tento compilar meu codigo.
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;[/b]
public class Conta {
private String nome;
private double credito;
Conta(){}
Conta(String nome, double credito){
this.nome = nome;
this.credito = credito;
}
public String getNome(){
return this.nome;
}
public double getCredito(){
return this.credito;
}
[b] // Metodo para escrever no arquivo.
public void escreveArquivo(ArrayList <Conta> contas) throws IOException{
Path path = Paths.get("d:/Pasta/contas.txt");
Charset utf8 = StandardCharsets.UTF_8;
// ésta linha abaixo é idenficada como a causadora o dos erros, será ? - Estas classes estão definidas logo acima no import.
try(BufferedWriter write = Files.newBufferedWriter(path,utf8)){
for(Conta conta : contas){
write.write(conta.nome + ";" + conta.credito);
}
}catch(IOException e){
e.printStackTrace();
}
}
} [/b]
Erros:
java.nio.file.NoSuchFileException: d:\Pasta\contas.txt
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source)
at java.nio.file.Files.newOutputStream(Unknown Source)
at java.nio.file.Files.newBufferedWriter(Unknown Source)
at br.com.xti.java.Conta.escreveArquivo(Conta.java:35)
at br.com.xti.java.Arquivo3.main(Arquivo3.java:23)
Se algum colega puder me ajudar , agradeço.