[英]access to environment variables in java
i want to do in my application a button that makes me enter in the list of environment variables in my system like the example below to enter in file system 我想在我的应用程序中执行一个按钮,使我可以像下面的示例一样在系统中输入环境变量列表以输入文件系统
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);
}
});
can anyone helpen me?? 谁能帮助我?
System.getenv()
gives you a simple map of environment variables : System.getenv()
为您提供环境变量的简单映射:
From Oracle doc : 从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));
}
}
}
I doubt that I can understand your question clearly, but there is a standard Oracle doc about working with env variables: 我怀疑我能否清楚地理解您的问题,但是有一个关于使用环境变量的标准Oracle文档:
http://docs.oracle.com/javase/tutorial/essential/environment/env.html http://docs.oracle.com/javase/tutorial/essential/environment/env.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.