where both the key and the value are strings
Environment Variables (The Java™ Tutorials > Essential Classes > The Platform Environment) https://docs.oracle.com/javase/tutorial/essential/environment/env.html
The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases.
Environment Variables
Many operating systems use environment variables to pass configuration information to applications. Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings. The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters. To learn how to pass environment variables to applications on your system, refer to your system documentation.
Querying Environment Variables
On the Java platform, an application uses System.getenv
to retrieve environment variable values. Without an argument, getenv
returns a read-only instance of java.util.Map
, where the map keys are the environment variable names, and the map values are the environment variable values. This is demonstrated in the EnvMap
example:
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));
}
}
}
With a String
argument, getenv
returns the value of the specified variable. If the variable is not defined, getenv
returns null
. The Env
example uses getenv
this way to query specific environment variables, specified on the command line:
public class Env {
public static void main (String[] args) {
for (String env: args) {
String value = System.getenv(env);
if (value != null) {
System.out.format("%s=%s%n",
env, value);
} else {
System.out.format("%s is"
+ " not assigned.%n", env);
}
}
}
}
Passing Environment Variables to New Processes
When a Java application uses a ProcessBuilder
object to create a new process, the default set of environment variables passed to the new process is the same set provided to the application's virtual machine process. The application can change this set using ProcessBuilder.environment
.
Platform Dependency Issues
There are many subtle differences between the way environment variables are implemented on different systems. For example, Windows ignores case in environment variable names, while UNIX does not. The way environment variables are used also varies. For example, Windows provides the user name in an environment variable called USERNAME
, while UNIX implementations might provide the user name in USER
, LOGNAME
, or both.
To maximize portability, never refer to an environment variable when the same value is available in a system property. For example, if the operating system provides a user name, it will always be available in the system property user.name
.
where both the key and the value are strings的更多相关文章
- golang Format string by key.
example: $ go get github.com/hoisie/mustache package main import ( "github.com/hoisie/mustache& ...
- 二、Redis基本操作——String(实战篇)
小喵万万没想到,上一篇博客,居然已经被阅读600次了!!!让小喵感觉压力颇大.万一有写错的地方,岂不是会误导很多筒子们.所以,恳请大家,如果看到小喵的博客有什么不对的地方,请尽快指正!谢谢! 小喵的唠 ...
- MapReduce 常见SQL模型解析
MapReduce应用场景 前一阵子参加炼数成金的MapReduce培训,培训中的作业例子比较有代表性,用于解释问题再好不过了.有一本国外的有关MR的教材,比较实用,点此下载. MR能解决什么问题?一 ...
- 昆仑游戏[JS加密修改]
昆仑游戏:http://www.kunlun.com/index.html JS加密修改 BigTools=window.BigTools;//重点 RSAKeyPair=window.RSAKeyP ...
- Redis缓存连接池管理
import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.util.Assert;import ...
- iOS各版本图标尺寸汇总
About Information Property List Files UILaunchImageFile UILaunchImageFile (String - iOS) specifies t ...
- 一周学会go语言并应用 by王奇疏
<一周学会go语言并应用> by王奇疏 ( 欢迎加入go语言群: 218160862 , 群内有实践) 点击加入 零.安装go语言,配置环境及IDE 这部分内容不多,请参考我的这篇安装环境 ...
- GoLang搞一个基本的HTTP服务
慢慢和python的对应一下看看. package main import ( "fmt" "net/http" "strings" &qu ...
- iOS10权限声明国际化
iOS 10要求用户声明隐私访问用途,而且不能为空,否则将会被拒.被拒邮件如下: 解决办法是在Info.plist中添加Privacy - Camera Usage Description和Priva ...
随机推荐
- location 将跟目录下某个文件夹指向2级目录
例如: /caffespressos/指向/web01/caffe/ [root@web01 default]# tree web01/ web01/ └── caffe └── index.html ...
- meta 标签的学习
meta name="viewport" content="width=device-width,initial-scale=1.0" 解释 <meta ...
- 本次安装Lion记录
黑苹果驱动之家 http://it360.org.cn/ Mac安装在Macintosh上是没什么好讲的,也没什么难度,原生的东西.但每次Mac安装在PC上总能折腾一番,驱动.五国.各种报错..今天记 ...
- jQuery新建HTML Element
举个例: 创建一个<i>HelloWorld.</i> var italicText = $("<i></i>").text(&qu ...
- android 获取屏幕高度和宽度 的方法
我们需要获取Android手机或Pad的屏幕的物理尺寸,以便于界面的设计或是其他功能的实现.下面就介绍讲一讲如何获取屏幕的物理尺寸 下面的代码即可获取屏幕的尺寸. 在一个Activity的onC ...
- 突破MIME限制上传
方法:找一个正常的可上传的查看其的MIME类型,然后将马子的MIME改成合法的MIME即可.
- qt setData()和data()
简述 在GUI开发中,往往需要在界面中存储一些有用的数据,这些数据可以来自配置文件.注册表.数据库.或者是Server. 无论来自哪里,这些数据对于用户来说都是至关重要的,它们在交互过程中大部分都会被 ...
- MDI多文档窗体--在一个窗体中装载多个窗体
创建MDI窗体之前,首先要明确两个概念:父窗体和子窗体,在MDI窗体中,起到容器作用的窗体被称为“父窗体”, 可放在父窗体中的其他窗体被称为子窗体,也成为MDI子窗体.当应用程序启动时,首先会显示父窗 ...
- ResourceBundle读取utf-8格式properties 中文乱码
解决方法: ResourceBundle prop = ResourceBundle.getBundle("app");String defaultTunnelName = new ...
- hive表分区的修复
hive从低版本升级到高版本或者做hadoop的集群数据迁移时,需要重新创建表和表分区,由于使用的是动态分区,所以需要重新刷新分区表字段,否则无法查看数据. 在hive中执行中以下命令即可自动更新元数 ...