我developp使用Windows桌面搜索的Java應用程序從中我能找回我的計算機上的文件的一些信息,比如URL(System.ItemUrl)。這種URL的一個例子是打開郵件使用協議「MAPI://」
file://c:/users/ausername/documents/aninterestingfile.txt
爲 「正常」 的文件。該欄位還提供從Outlook或Thunderbird索引的郵件項目的網址。 Thunderbird的項目(僅適用於Vista和7)也是文件(.wdseml)。但前景的項目網址開頭爲「MAPI://」,如:
mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가
我已經使用這個網址從Java是開放Outlook中的實際項目的問題。如果我將它複製/粘貼到Windows的運行對話框中,它就會起作用;如果我使用「start」,然後在命令行中複製/粘貼的url,它也可以工作。
該網址似乎以UTF-16編碼。我希望能夠寫出這樣的代碼:
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
Runtime.getRuntime().exec("cmd.exe /C start " + url);
我不工作,我已經嘗試過其他解決方案,如:
String start = "start";
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
FileOutputStream fos = new FileOutputStream(new File("test.bat");
fos.write(start.getBytes("UTF16");
fos.write(url.getBytes("UTF16"));
fos.close();
Runtime.getRuntime().exec("cmd.exe /C test.bat");
沒有任何成功。使用上面的解決方案,文件「下的test.bat」包含了正確的網址上的「開始」命令,但在衆所周知的錯誤信息「下的test.bat」的結果來看:
'■' is not recognized as an internal or external command, operable program or batch file.
有沒有人的能夠打開來自Java的「mapi://」項目的想法?
什麼繞道而行!爲什麼exec(cmd)? Java有沒有辦法調用COM對象?那麼你應該能夠導入WScript.Shell'的'類型庫(該推移的全名'Windows腳本宿主對象Model')和直接調用運行。 – 2015-09-23 06:07:26