Posted By:
Benoit_Caron
Posted On:
Wednesday, August 25, 2004 07:24 AM
How do i get attachment? here is my problem: when my program try to download attachment (i use the saveFile method from an other message in this forum) public static void saveFile(String filename, InputStream input) throws IOException { if (filename == null) { filename = File.createTempFile("xx", ".out").getName(); } // Do no overwrite existing file File file = new File(filename); for (int i=0; file.exists(); i++) { file = new File(filename+i); } FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); BufferedInputStream bis = new Buff
More>>
How do i get attachment?
here is my problem:
when my program try to download attachment (i use the saveFile method from an other message in this forum)
public static void saveFile(String filename,
InputStream input) throws IOException {
if (filename == null) {
filename = File.createTempFile("xx", ".out").getName();
}
// Do no overwrite existing file
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
}
bos.flush();
bos.close();
bis.close();
}
I either have a smaller attachment (when trying to get a texte attachment) or an IOException (when it isn't texte) and so have a corrupted file on my disk.
java.io.IOException
: Error in encoded stream: needed 4 valid base64 characters b
ut only got 3 before EOF, the valid characters were: "ujB"
at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java
:179)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:7
8)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:1
03)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at Boite.savePieceJointe(Boite.java:250)
at Boite.verifier(Boite.java:193)
at Tache.verifier_boite(Tache.java:98)
at Tache.run(Tache.java:76)
I don't understand ???
<<Less