🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: �Escribir a disco los ficheros adjuntos de un e-mail?

#25606
From: Socram
Date: Wed, 17 Mar 1999 00:00
41 lines
2138 bytes
>  for(int i = 0; i <msg.length; i++) {
>   from = msg[i].getFrom()[0].toString();
>   subject = msg[i].getSubject();
>   contentType = msg[i].getContentType();
>   contenido = (Multipart)msg[i].getContent();
>   nBodyPart = contenido.getCount();
>   for(int j = 0; j < nBodyPart; j++) {
>    bp = contenido.getBodyPart(j);
>    if(bp.getContentType().indexOf("application/") != -1) {
>     fileName = bp.getFileName();
>     dh = bp.getDataHandler();


    esto en principio debe funcionar bien, ya que segun la api del JAF es
como se recupera un archivo adjunto. Lo que te devuelve es el Stream que tu
ya has pasado. Solo una cosa, estas seguro que no es el getOutputStream? Lo
has probado no?

>     isr = new InputStreamReader(dh.getInputStream());
>     buf = new StringBuffer();
>     // Puede ser que est� obteniendo mal los datos del input stream?


    si lo anterior no funciona prueba a leer todos los bytes que tienes en
el fichero que recoges en un byte[] y luego los escribes directamente en el
fichero de salida. Es menos engorroso y mas comodo.

>     while((bytes_read = isr.read(data)) > 0)
>      buf.append(data, 0, bytes_read);
>     archivo = new File(fileName);
>     archivoSalida = new DataOutputStream(new FileOutputStream(archivo));
>     archivoSalida.writeBytes(new String(buf));
>     archivoSalida.close();


Saludos y mantenme informado de donde estaba el fallo:

Socram -----> uov02127@correo.uniovi.es
-------------------------------------------------------------------------
Bajo el nogal de ramas extendidas
yo te vendi y tu me vendiste. George Orwell
Technical Details
Message-ID: <7cp65k$gu0$1@diana.bcn.ttd.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7cmhv4$cuc$1@talia.mad.ttd.net>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: 1116f3,86304c1cb21c360d,start
X-Google-Attributes: gid1116f3,public
From: "Socram" <uov02127@correo.uniovi.es>
Subject: Re: �Escribir a disco los ficheros adjuntos de un e-mail?
Date: 1999/03/17
Message-ID: <7cp65k$gu0$1@diana.bcn.ttd.net>
X-Deja-AN: 455869083
References: <7cmhv4$cuc$1@talia.mad.ttd.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Telefonica Transmision de Datos
Newsgroups: es.comp.lenguajes.java