मैं उन संलग्नक भेज सकता हूं जिनमें जावामेल में गैर-असीसी फ़ाइल नाम हैं लेकिन मैं उन्हें डाउनलोड करने में सक्षम नहीं हूं। मुझे java.io.FileNotFoundException विशेष रूप से उन अनुलग्नकों के लिए मिल रहा है जिनके फ़ाइल नामों में गैर-असीसी वर्ण हैं।फ़ाइल नामों में जावामेल और गैर-ASCII वर्ण
FYI करें: मैं पाठ को एन्कोड करने messageBodyPart.setFileName(MimeUtility.encodeText(filename[i]))
की तरह कुछ का उपयोग कर रहा है और MimeUtility.decodeText(bodyPart.getFileName())
गैर- ASCII फ़ाइल नाम
इसके लिए एक समाधान है डिकोड करने के लिए?
संपादित करें @ बिल, यहां मेरे कोड का हिस्सा है जो अनुलग्नक पढ़ता है। मैंने गुणों को भी जोड़ा है .setProperty ("mail.mime.decodeparameters", "true") और Properties.setProperty ("mail.mime.decodefilename", "true") मेरे कोड में गुण।
if (message[a].getContent() instanceof MimeMultipart) {
Multipart multipart = (Multipart) message[a].getContent();
for (int i = 0; i < multipart.getCount(); i++) {
bodyPart = multipart.getBodyPart(i);
disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT) || (disposition.equals(BodyPart.INLINE)))) {
DataHandler handler = bodyPart.getDataHandler();
String path = bodyPart.getFileName();
String[] str = path.split("/");
String fileName = str[str.length - 1];
String filePath = ReadConfigPropertiesFile.getPropertyValue("server.buildpath");
System.out.println(fileName);
File tempDir = new File(filePath + user);
if (!tempDir.exists()) {
tempDir.mkdir();
}
File saveFile = new File(tempDir + "/" + fileName);
int count = 0;
while (saveFile.exists()) {
count++;
saveFile = new File(tempDir + "/" + count + "_" + fileName);
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveFile));
byte[] buff = new byte[2048];
InputStream is = bodyPart.getInputStream();
int ret = 0;
while ((ret = is.read(buff)) > 0) {
bos.write(buff, 0, ret);
}
bos.close();
is.close();
//System.out.println(bodyPart.getContentType());
}else {
//display body (message) of the attachment;
//System.out.println(bodyPart.getContent().toString());
}
}
}
ऊपर कोड BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveFile))
लाइन पर FileNotFoundException अपवाद को जन्म देती है और इस संलग्नक जिसका फ़ाइल नाम गैर- ASCII वर्ण (ሰላም। जैसे पीडीएफ कुछ कर रहे हैं) के लिए उठाया जा रहा है। हर चीज ठीक काम करती है।
अभी भी मेरी समस्या को हल करने के लिए संघर्ष कर रहा है। कोई सुधार? – semytech
इस बिंदु पर यह जावामेल समस्या नहीं है इसलिए मैं बहुत मदद नहीं दे सकता। यह शायद नीचे है कि आपका ऑपरेटिंग सिस्टम गैर-ASCII वर्णों के साथ फ़ाइल नामों से कैसे संबंधित है। आप समस्या को पुन: उत्पन्न करने के लिए एक मामूली स्टैंडअलोन जावा प्रोग्राम लिख सकते हैं। फ़ाइल बनाने के दौरान आपको फ़ाइल नाम एन्कोड करने की आवश्यकता हो सकती है यदि आपका ऑपरेटिंग सिस्टम इसे संभाल नहीं पाएगा। –
ठीक है धन्यवाद। मैं इसके लिए सरल जावा प्रोग्राम बनाकर इसे देखूंगा और आपको बता दूंगा। – semytech