Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LeerArchivios
- package archivos;
- import java.io.FileInputStream;
- import java.io.IOException;
- public class LeerArchivo {
- public void leer_desde_archivo_Bytes(String nombre_archivo) {
- try {
- FileInputStream r = new FileInputStream(nombre_archivo);
- //Obtiene la cantidad de bytes del archivo
- int a = r.available();
- int nByte = 0;
- int d = r.read();
- while ( d != -1) {
- ++nByte;
- System.out.print( (char) d);
- d = r.read();
- }
- r.close();
- System.out.println("\n Cantidad de Bytes leidos =" + nByte);
- System.out.println("Cantidad de Bytes en el archivo =" + a);
- } catch (IOException e) {
- System.out.println("\n### IO Error: " + e);
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- }
- }
- --EscribirArchivos
- package archivos;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class EscribirArchivo {
- public void escribir_archivo_Byte(String nombre_archivo) {
- try {
- FileOutputStream r = new FileOutputStream(nombre_archivo);
- int nByte = 0;
- int d = System.in.read();
- while(d != 4) {
- ++nByte;
- r.write(d);
- d = System.in.read();
- }
- r.close();
- } catch (IOException e) {
- System.out.println("\n### IO Error: " + e);
- }
- }
- }
- --Main
- package archivos;
- public class TesterLeerArchivo {
- public static void main(String[] args) {
- LeerArchivo la = new LeerArchivo();
- la.leer_desde_archivo_Bytes("D:\\Usil\\POO\\Semana 10\\Parte A\\prueba.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement