I have created a Java application where a user can drag and drop a file to save it into a specified folder. I am using FileDrop
and unfortunately it doesn't work with emails dragged and dropped directly from Outlook. It works when the email is dropped to the desktop first (a .eml file is created) and then dropped into the application, but I really want to bypass this step.
You can see my code below:
new FileDrop(panel, new FileDrop.Listener() {
public void filesDropped(java.io.File[] files) {
for (int i=0; i<files.length; i++) {
File newFile = files[i];
byte[] myByteArray = null;
try { //get the data of the file into a byte array
myByteArray = org.apache.commons.io.FileUtils.readFileToByteArray(newFile);
} catch (IOException e1) {
e1.printStackTrace();
}
String newFileName = newFile.getName();
try { //create the file
FileOutputStream file = new FileOutputStream("projects/"+ newFileName);
file.write(myByteArray);
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
I would love to hear any possible solutions to this problem.
By the way, this is part of the error message I am getting, pointing out that the problem occurs in the public void filesDropped(java.io.File[] files) {
line, since the email that was dropped into the application is not recognized as a file yet (I guess).
...
2015-06-04 12:10:50.860 java[718:71442] Couldn't get a copy of an HFS Promise from the pasteboard
2015-06-04 12:10:50.860 java[718:71442] Looked for HFSPromises on the pasteboard, but found none.
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.<init>(File.java:363)
at net.iharder.dnd.FileDrop.createFileArray(FileDrop.java:453)
...
Thanks in advance.