Fórum Pacote java.io #561694
29/08/2016
0
Boa noite pessoal,firmeza?
Estou iniciando agora em programação orientada a objetos e estou com um problema.Preciso carregar um arquivo txt em meu HD para fazer a contagem de palavras,vogais,consoantes,linhas e espaços em branco.Porém a principio tentei carregar meu arquivo e está dando erro.Postarei o código para análise.Desde já agradeço a força.
package entradatxt;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author C
*/
public class EntradaTxt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
System.out.printf("Entrada.txt:\\n");
String nome = ler.nextLine();
System.out.printf("\\nC:\\\\Users\\\\C\\\\Documents\\\\PAS-POO:\\n");
try{
FileReader arq = new FileReader(nome);
BufferedReader lerArq = new BufferedReader(arq);
String linha = lerArq.readLine();
while (linha!=null){
System.out.printf("%s\\n", linha);
linha = lerArq.readLine();
}
arq.close();
}catch (IOException e){
System.err.printf("Erro na abertura do arquivo:%s.\\n",
e.getMessage());
}
}
}
Estou iniciando agora em programação orientada a objetos e estou com um problema.Preciso carregar um arquivo txt em meu HD para fazer a contagem de palavras,vogais,consoantes,linhas e espaços em branco.Porém a principio tentei carregar meu arquivo e está dando erro.Postarei o código para análise.Desde já agradeço a força.
package entradatxt;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author C
*/
public class EntradaTxt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
System.out.printf("Entrada.txt:\\n");
String nome = ler.nextLine();
System.out.printf("\\nC:\\\\Users\\\\C\\\\Documents\\\\PAS-POO:\\n");
try{
FileReader arq = new FileReader(nome);
BufferedReader lerArq = new BufferedReader(arq);
String linha = lerArq.readLine();
while (linha!=null){
System.out.printf("%s\\n", linha);
linha = lerArq.readLine();
}
arq.close();
}catch (IOException e){
System.err.printf("Erro na abertura do arquivo:%s.\\n",
e.getMessage());
}
}
}
Paulo
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)