Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.util.Scanner;
- public class SalvaArquivo {
- public static void main (String [] args){
- Scanner scanner = new Scanner (System.in);
- System.out.print("Digite o texto: ");
- String texto = scanner.nextLine();
- escreveArquivo(texto);
- String textoLido = leArquivo();
- contaVogais(textoLido);
- scanner.close();
- }
- /*-*/
- public static void escreveArquivo(String texto) {
- System.out.println("Escrevendo no arquivo a string: " + texto);
- try {
- Files.write (Paths.get ("/Users/Aluno.SSA-D-CPIL01-11/Desktop/teste/teste.txt"), texto.getBytes());
- } catch (Exception e){
- System.out.println ("Erro: " + e);
- }
- }
- /*-*/
- public static String leArquivo () {
- System.out.println("Lendo arquivo: ");
- String textoLido = null;
- try {
- FileReader fileReader = new FileReader("C:/Users/Aluno.SSA-D-CPIL01-11/Desktop/teste/teste.txt");
- BufferedReader buffReader = new BufferedReader(fileReader);
- textoLido = buffReader.readLine();
- } catch (Exception e) {
- System.out.println("Erro: " + e);
- }
- System.out.println(textoLido);
- return textoLido;
- }
- /*-*/
- public static void contaVogais(String texto) {
- String textoCaps = texto.toUpperCase();
- System.out.println (textoCaps);
- int vogais = 0;
- for (int i = 0; i < textoCaps.length(); i ++) {
- char c = textoCaps.charAt(i);
- if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
- vogais ++;
- }
- System.out.println ("Quantidade de vogais: " + vogais);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement