Open txt file within a folder and edit file information

0

The design of a clinic is already registering and listing the patients and their respective txt files, now the doctor will see all the patients listed and he has to enter the full patient name, which is just the name of the txt file. When doing this he is writing the file name and trying to open it to add the exam information, but he does not find the files in the folder.

public void listar_exame() throws IOException{
    System.out.printf("############ LISTA DE PACIENTES ############\n");
    String caminhoPasta = "C:\Users\Dhyego\Dropbox\Projeto Software\Main\Consultas";

    Files.walk(Paths.get(caminhoPasta)).forEach(filePath -> {
        if (Files.isRegularFile(filePath)) {
            System.out.println(filePath.getFileName().toString());
        }
    });

}

public void abrir_exame(){

System.out.printf("Digite o nome completo do paciente: ");
nome = ler.next();
nomeArq = nome +".txt";
File arq = new File(nomeArq);
//Arquivo existe
if (arq.exists()){
    String mostra = "Arquivo - '"+nomeArq+"', aberto com sucesso!\n";
  mostra+="Tamanho do arquivo "+Long.toString(arq.length())+"\n";
  //tentando ler arquivo
  try{
    mostra+="Conteudo:\n";
    //abrindo arquivo para leitura
    FileReader reader = new FileReader(nomeArq);
    //leitor do arquivo
    BufferedReader leitor = new BufferedReader(reader);
    while(true){
        String linha = leitor.readLine();
      if(linha==null)
        break;
      mostra+=linha+"\n";
    }
  }
  catch(Exception erro) {
    System.out.printf("Erro ao abrir o arquivo "+erro);

  }

}else{
    System.out.printf("Arquivo nao existe \n");
}
}

OUTPUT:

    
asked by anonymous 21.06.2016 / 17:05

0 answers