leer archivos en java


package archivo;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author yesidsanchezer
 */
public class leer {
 
    public void lee(){
     
        try {
            FileReader entrada= new FileReader("C:\\Users\\yesidsanchezer\\Desktop\\fichero.txt");
            int c = entrada.read();
         
            while (c!=-1) {
           
                c= entrada.read();
             
                char letra = (char)c;
                System.err.print(letra);
             
            }
        } catch (IOException ex) {
            System.err.println("no se encontro el archivo");
        }
    }
}




package archivo;

/**
 *
 * @author yesidsanchezer
 */
public class Archivo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        leer leet = new leer();
        
        leet.lee();
    }
    
}



Previous
Next Post »