Lendo XML anexo de e-mail - ao salvar, coloca arquivos estranhos

0 respostas
H

Caros, boa tarde.

Estou lendo uma caixa de e-mail que recebe nossos arquivos de nota fiscal eletrônica (XML).
Leio a caixa de entrada e, quando salvo o arquivo anexo está colocando caracteres especiais no inicio do arquivo, impossibilitando uma leitura posterior que tenho também via java.

Vocês tem alguma sugestão?

Abaixo o código que salva o arquivo…

folder.open(Folder.READ_WRITE);
		  Message[] messages = folder.getMessages();
		  for (int a = 0; a < messages.length; a++) 
		  { 
				if (!messages[a].isSet(Flags.Flag.SEEN) && !messages[a].isSet(Flags.Flag.ANSWERED)) 
				{
					try{ 
						
						Multipart multipart = (Multipart) messages[a].getContent();    
						  for (int i = 0; i < multipart.getCount(); i++) {
							  
							  BodyPart bodyPart = multipart.getBodyPart(i);           
							  InputStream is = bodyPart.getInputStream();
							  File f = new File(cPastaSalvaXml + "/" + bodyPart.getFileName());
							  System.out.println("Anexo: " + bodyPart.getFileName());
							  FileOutputStream fos = new FileOutputStream (f);  
							  BufferedOutputStream bos = new BufferedOutputStream (fos);  
							  BufferedInputStream bis = new BufferedInputStream (is);  
							  int fByte;  
							  while ((fByte = bis.read ())!= -1) {  
							  bos.write (fByte);  
							  }  
							  bos.flush ();  
							  bos.close ();  
							  bis.close ();  
							  fos.close();
						  }
					}
				}
		  }
Criado 9 de outubro de 2012
Respostas 0
Participantes 1