Article View: es.comp.lenguajes.java
Article #28656read ( byte [] ) problemilla
From: javier sanz
Date: Mon, 06 Apr 1998 00:00
Date: Mon, 06 Apr 1998 00:00
65 lines
1992 bytes
1992 bytes
Buenas !!!
Tengo una duda.
El problema trata de leer un fichero de datos, ya sea ascii o binario,
lo que sea.
Usando la funcion read() resulta que el ultimo bloque de bytes si no es
multiplo del
tamaοΏ½o del buffer de bytes no es leido, ademas de no generar ninguna
excepcion.
El problema lo he resulto generando antes de cada lectura el buffer de
bytes.
Hay alguna otra forma de arreglarlo, porque debo de hacer new byte []
antes de cada lectura.
-----------------------------------------------------------------------------------------------
import java.io.* ;
class a
{
public static void main ( String args[] )
{
DataInputStream entrada ;
int pos, quedan ;
byte buffer [] = new byte [1024];
try
{
entrada = new DataInputStream (
new FileInputStream ( "/fuentes/person.c") );
while ( ( quedan = entrada.available() ) > 0 )
{
if ( quedan > buffer.length )
quedan = buffer.length ;
System.out.println ( "quedan " + quedan );
buffer = new byte [ quedan ] ; // SI ELEMINAS ESTA LINEA NO
DEVUELVE EL ULTIMO BUFFER
entrada.read( buffer, 0 , quedan ) ;
System.out.println ( "->" + new String ( buffer,0 ));
}
}
catch ( EOFException e )
{
System.out.println ( " Fin Fichero ..");
}
catch ( IOException e )
{
System.out.println ( " Algo raro en el Fichero ..");
}
}
}
----------------------------------------------------------------------------------------------
please, cc to jsa55@tid.es
Javier Sanz
Technical Details
Message-ID:
<3528C810.AF4308AB@tid.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: 1116f3,8a46be540d924964,start X-Google-Attributes: gid1116f3,public From: javier sanz <jsa55@tid.es> Subject: read ( byte [] ) problemilla Date: 1998/04/06 Message-ID: <3528C810.AF4308AB@tid.es> X-Deja-AN: 341331177 Content-Transfer-Encoding: 8bit Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Organization: tid Newsgroups: es.comp.lenguajes.java