首先,看看有什麼在DragBoard:
Dragboard db = event.getDragboard();
db.getContentTypes().forEach(df -> System.out.println(df + " - " + db.getContent(df)));
你得到這樣的輸出:
[文/ X-MOZ-URL] - 我
[應用程序/ x -moz-file-promise] - null
[text/x-moz-message] - i
[application/x-moz-file-promise-url] - java.nio.HeapByteBuffer [pos = 0 lim = 200帽= 200]
[_NETSCAPE_URL] - java.nio.HeapByteBuffer [POS = 0 LIM = 63帽= 63]
(在這個例子中我拖着從FossaMail郵件)
這告訴你的MIME類型(應用/ X- moz-file-promise-url)和類(HeapByteBuffer):
DataFormat df = DataFormat.lookupMimeType("application/x-moz-file-promise-url");
ByteBuffer buffer = (ByteBuffer) db.getContent(df);