Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File arquivoEscrever = new File("C://POO - Lista 01 - Resulados/ExercicioSeis.txt");
- try
- {
- if(!arquivoEscrever.exists()) {
- arquivoEscrever.createNewFile();
- System.out.println("Arquivo " + arquivoEscrever + " criado com sucesso.");
- } else {
- System.out.println("Arquivo " + arquivoEscrever + " já existe");
- }
- File[] arquivos = arquivoEscrever.listFiles();
- FileWriter fw = new FileWriter(arquivoEscrever, true);
- BufferedWriter bw = new BufferedWriter(fw);
- 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);
- bw.newLine();
- bw.close();
- fw.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- File arquivoLer = new File("C://POO - Lista 01 - Resulados/ExercicioSeis.txt");
- try
- {
- if(!arquivoLer.exists()) {
- arquivoLer.createNewFile();
- }
- FileReader fr = new FileReader(arquivoLer);
- BufferedReader br = new BufferedReader(fr);
- while(br.ready()) {
- System.out.println(br.readLine());
- }
- br.close();
- fr.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement