2013-08-01 65 views
0

我想在我的應用程序做一個按鈕,讓我在環境變量列表在我的系統 進入如下面的例子在文件系統獲取環境變量在Java

    b = new Button(dialog, SWT.PUSH); 
       b.setText("Browse file system"); 
        b.addSelectionListener(new SelectionAdapter() { 
    @Override 
    public void widgetSelected(SelectionEvent e) { 
    DirectoryDialog fileDialog = new DirectoryDialog(parent); 
    fileDialog.setFilterPath(pathText.getText()); 
    String file = fileDialog.open(); 
    if (file != null) { 
     File workspace = ResourcesPlugin.getWorkspace().getRoot() 
      .getLocation().toFile().getAbsoluteFile(); 

     String workspacePath = workspace.toString(); 
     if (file.contains(workspacePath)) 
     file = file.replace(workspacePath, "$WORKSPACE") 
      .replace("\\", "/"); 
     pathText.setText(file); 
    } 
    super.widgetSelected(e); 
    } 
}); 

任何人都可以進入幫助我?

回答

0

System.getenv()給你的環境變量的簡單地圖:

Oracle doc

import java.util.Map; 

public class EnvMap { 
    public static void main (String[] args) { 
    Map<String, String> env = System.getenv(); 
    for (String envName : env.keySet()) { 
     System.out.format("%s=%s%n", 
          envName, 
          env.get(envName)); 
    } 
    } 
} 
+0

感謝您的回覆,但我有另一個問題,我嘗試使用fonctio n: – ange