Advertisement
Guest User

Untitled

a guest
Aug 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. File arquivoEscrever = new File("C://POO - Lista 01 - Resulados/ExercicioSeis.txt");
  2. try
  3. {
  4. if(!arquivoEscrever.exists()) {
  5. arquivoEscrever.createNewFile();
  6. System.out.println("Arquivo " + arquivoEscrever + " criado com sucesso.");
  7. } else {
  8. System.out.println("Arquivo " + arquivoEscrever + " já existe");
  9. }
  10.  
  11. File[] arquivos = arquivoEscrever.listFiles();
  12. FileWriter fw = new FileWriter(arquivoEscrever, true);
  13. BufferedWriter bw = new BufferedWriter(fw);
  14. bw.write("Maior preço informado: " + maiorPreco + "%." + "\nMenor preço informado: " + menorPreco + "%." + "\nMaior desconto informado: " + maiorDesconto + "%." + "Menor Desconto informado: " + menorDesconto + "%." + "\nA média de todos os preços informados é igual a: " + mediaPrecos);
  15. bw.newLine();
  16. bw.close();
  17. fw.close();
  18. } catch (IOException ex) {
  19. ex.printStackTrace();
  20. }
  21.  
  22. File arquivoLer = new File("C://POO - Lista 01 - Resulados/ExercicioSeis.txt");
  23. try
  24. {
  25. if(!arquivoLer.exists()) {
  26. arquivoLer.createNewFile();
  27. }
  28. FileReader fr = new FileReader(arquivoLer);
  29. BufferedReader br = new BufferedReader(fr);
  30. while(br.ready()) {
  31. System.out.println(br.readLine());
  32. }
  33. br.close();
  34. fr.close();
  35. } catch (IOException ex) {
  36. ex.printStackTrace();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement