TAREA: PROGRAMA PARA CONTAR LINEAS Y PALABRAS
Enviado por Attested • 25 de Marzo de 2019 • Tarea • 632 Palabras (3 Páginas) • 65 Visitas
TAREA: PROGRAMA PARA CONTAR LINEAS Y PALABRAS.
CLASE:
package lec_lineas_y_palabras;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Attested
*/
public class lec_lineas_y_palabras {
private File fichero;
private String contenido;
public lec_lineas_y_palabras(){
}
public lec_lineas_y_palabras(File fichero){
this.fichero=fichero;
this.contenido="";
leerContenido();
}
public void leerContenido(){
String linea=null;
FileReader f=null;
BufferedReader b=null;
try{
f = new FileReader(this.fichero);
b = new BufferedReader(f);
try{
while ((linea = b.readLine())!=null)
this.contenido = this.contenido + "" + linea + "\n";
}
catch (IOException ex){
Logger.getLogger(principal.class.getName()).log(Level.SEVERE,null,ex);
}
}
catch (FileNotFoundException ex){
Logger.getLogger(principal.class.getName()) .log(Level.SEVERE,null,ex);
}
}
public String getContenido(){
return contenido;
}
public int getLinea(){
if(this.contenido.equals(""))
return 0;
else
return this.contenido.split("\n").length;
}
public int getPalabra(){
if(this.contenido.equals(""))
return 0;
else{
//StringTokenizer at = new StringTokenizer(this.contenido.replace("\n"," "));
...