Java - problema con flujos al enviar archivos

 
Vista:

problema con flujos al enviar archivos

Publicado por daniel (1 intervención) el 15/08/2007 15:29:06
hola!!
necesito ayuda...tengo armado un chat y le estoy agregando una parte donde el usuario puede subir archivos al servidor...
el tema es que el servidor no reconoce donde termina el archivo por lo que le mando un mensaje antes de enviar cada parte del buffer al servidor...pero no se q pasa..

Cliente

File file=new File (Archivo);
FileInputStream archivoaenviar = null;
try {
archivoaenviar = new FileInputStream(Archivo);
} catch (FileNotFoundException e1)
{
procesos.errorFatal(e1,"error al buscar el archivo");
}
byte[] buf = new byte[1024];
int len=0;
try {
while ((len = archivoaenviar.read(buf)) > 0)
{
procesos.salida.println("paquete2184");
System.out.println("se entro a donde se lee buffer" + buf);
procesos.salida.write(buf, 0, len);
}
} catch (IOException e1) {
e1.printStackTrace();
}
archivoaenviar.close();
System.out.println("seenviaarchivo");

SERVER

if (textoUsuario.equals("seenviaarchivo2184"))
{
salida.println("serecibepeticiondeupload2184");
System.out.println("se entro al metodo q recibe el archivo");
//CREO LA INSTANCIA PARA ESCRIBIR EL ARCHIVO EN DISCO
FileOutputStream out = null;
try {
out = new FileOutputStream(new java.io.File("C:\\llego.txt"));
System.out.println("se creo la salida a un archivo");
} catch (FileNotFoundException e) {
errorFatal(e,"error al generar el archivo de recepcion file not found");
}
byte[] buf = new byte[1024];
int len=0;
System.out.println("casi entra al try del while q lee el buffer");
try {
while ( (textoUsuario=entrada.readLine()) == "paquete2184" )
System.out.println("entro al while del paquete");
while((len = entrada.read(buf)) > 0)
System.out.println("se entro a donde se lee buffer" + buf);
out.write(buf, 0, len);
break;
}
}
} catch (IOException e) {
errorFatal(e,"error al leer el buffer del archivo recibido");
}
try {

out.close();
} catch (IOException e) {
errorFatal(e,"error al cerrar flujos o al crearlo");
}
out.close();
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder