Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/06/2009, 02:47
Jeibi
 
Fecha de Ingreso: noviembre-2007
Ubicación: Madrid
Mensajes: 96
Antigüedad: 16 años, 6 meses
Puntos: 2
Respuesta: ¿Cómo leo un elemento type="file" en un servlet?

Hola, gracias por vuestra ayuda.

He hecho lo siguiente:

Código:
String adjunto = req.getParameter("adjunto");
String ruta = "c:/";
String archivo = ruta + adjunto;
int buffer= 2048;
byte data[] = new byte[buffer];
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(archivo));
BufferedInputStream bis = new BufferedInputStream(new DataInputStream(req.getInputStream()));
int count;
while ((count = bis.read(data, 0, buffer)) != -1) {
	bos.write(data, 0, count);
}
bos.flush();
bos.close();
bis.close();
Con esto consigo grabar un archivo en la ruta que le pongo pero esta vacio, con 0 bytes. Es como si el archivo que le paso estuviera vacio, que llega solo el nombre. ¿Alguien sabe porqué no funciona?

gracias