I am trying to send mail with byte array which is compressed by GZIP, and then rename it with **.csv.gz. I can not open the **.csv file, however, and it shows the file is broken.
I sent it by the following code:
ByteArrayOutputStream obj = new ByteArrayOutputStream();
gzipOS = new GZIPOutputStream(obj);
gzipOS.write(content.getBytes());//content is csv format
byte[] data = obj.toByteArray();
return data;
I tried many mime types, but it does not work:
DataSource dataSource2 = new ByteArrayDataSource(data, "text/plain");
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(dataSource2));
messageBodyPart.setFileName("kk.csv.gz");
This attachment is sent successfully, but when I open it with 7-zip, and try to compress it, it shows this file is broken.
Is there any way to slove this problem?
I think this is caused by the formatting when I rename it with **.csv.gz but **.csv.gz is necessary.
Tips: disk is not allowed to save the file, so I send it by this way.