🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #28250

Q: Lectura de fiechero binario

#28250
From: Rafael Garcia Leiva
Date: Mon, 11 May 1998 00:00
45 lines
1437 bytes
	Hola!

	Tengo un fichero binario, que puedo leerlo perfectamente desde C,
pero con java tengo problemas (trabajo con Solaris)
	El fuente en C es el siguiente:

main() {
    FILE *fp;
    int lsb, msb;
    int agno;

    fp = fopen( "97280a14.hrp", "rb" );

    lsb = (int)getc(fp);
    msb = (int)getc(fp);
    agno = msb * 256 + lsb;
    (void)printf( "lsb: %d\n", lsb );
    (void)printf( "msb: %d\n", msb );
    (void)printf( "A�o: %d\n", agno );
 
    (void)fclose( fp );
}

que da el siguiente resultado:

lsb: 205
msb: 7
A�o: 1997


Utilizando el programa java:

int lsb, msb;
int a�o;

InputStream fich = new FileInputStream( "97280a14.hrp" ); 
DataInputStream in = new DataInputStream( fich );

lsb = (int)in.readByte();
msb = (int)in.readByte();
a�o = ( (msb * 256) + lsb );
System.out.println( "lsb: " + lsb );
System.out.println( "msb: " + msb );
System.out.println( "A�o: " + a�o );
Technical Details
Message-ID: <6j6j3p$qvb$1@erika.cica.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1116f3,755beee34340d88a,start
X-Google-Attributes: gid1116f3,public
From: cc1galer@uco.es (Rafael Garcia Leiva)
Subject: Q: Lectura de fiechero binario
Date: 1998/05/11
Message-ID: <6j6j3p$qvb$1@erika.cica.es>
X-Deja-AN: 352205213
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Organization: Centro Informatico Cientifico de Andalucia
Mime-Version: 1.0
Newsgroups: es.comp.lenguajes.java