2014-09-25 75 views
0

是否可以使用(thunderbird,outlook等)來獲取默認郵件客戶端的名稱? desktop.mail()打開默認的郵件客戶端。但是java在哪裏讀取哪個是默認的郵件客戶端?java獲取默認郵件程序的名稱

此致

+0

我推測會成爲Java之外的關注;發送一個'mailto'鏈接並讓操作系統上配置的郵件客戶端處理它。 – Makoto 2014-09-25 15:35:24

回答

0

已解決。

我可以得到默認郵件客戶端的註冊表vaue:

package side_pakets; 

import java.io.IOException; 
import java.io.InputStream; 
import java.io.StringWriter; 

public class Read_Win_Registry 
{ 
    String output; 
    String input; 
    String location = "HKEY_CURRENT_USER\\Software\\Clients\\Mail"; 
    /** 
    * 
    * @param location 
    *   path in the registry 
    * @param /ve returns default registry values 
    * 
    */ 
    public String readRegistry(String location) 
    { 
     try 
     { 
      Process process = Runtime.getRuntime().exec(
        "reg query " + location + " /ve "); 

      StreamReader reader = new StreamReader(process.getInputStream()); 
      reader.start(); 
      process.waitFor(); 
      reader.join(); 
      output = reader.getResult(); 

     } catch (Exception e) 
     { 
      // return null; 
     } 
     return output; 

    } 

    static class StreamReader extends Thread 
    { 
     private InputStream is; 
     private StringWriter sw = new StringWriter(); 

     public StreamReader(InputStream is) 
     { 
      this.is = is; 
     } 

     public void run() 
     { 
      try 
      { 
       int c; 
       while ((c = is.read()) != -1) 
        sw.write(c); 
      } catch (IOException e) 
      { 
      } 
     } 
    } 

}