System.setProperty和System.getProperty [英] System.setProperty and System.getProperty

查看:120
本文介绍了System.setProperty和System.getProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 System.setProperty 来定义存储数据的参数时,我不明白?

I didn't understand when I used System.setProperty to define a parameter, where the data is stored?

如果说我在一个java文件中使用了 System.setProperty ,那么我可以在任何地方使用这些属性吗?但事实并非如此,我不能在任何地方使用它,只能在我称为 setProperty 的同一个java文件中。

If say that I used System.setProperty in one java file, then can I use the properties anywhere? But this is not true, I can't use it anywhere, only in the same java file I called setProperty.

我真的不知道为什么以及这个方法的功能是什么。

I really do not know why and what the function of this method is.

推荐答案

系统 class有一个名为props的 static 成员变量,其类型为 Properties 。除此之外,属性 Hashtable 类的子类型。所有属性值都存储为Key和Value。所以,数据存储区是Hashtable 。解答另一个问题,你可以很好地使用 System.getProperty(propertyKey)方法您的应用程序,因为它是一个公共静态方法。你还没有理解java程序是如何工作的。 运行Java程序时,实际上是在启动JVM实例。该实例将具有自己的系统属性。那是你必须把你的财产。当您运行其他程序时,它将具有自己的系统属性。所以,你不能指望你在一个JVM实例中设置的属性可以从另一个JVM实例访问!你可以访问 System.getProperty(propertyKey)在同一JVM实例中运行的所有类中。希望你能理解!

System class has a static member variable named props which is of type Properties. Adding to that, Properties is a subtype of Hashtable class. All the property values are stored as Key and Value. So, datastore is Hashtable.Answering the other question, You can very well use System.getProperty(propertyKey) method throughout your application since it is a public static method. You haven't understood how java programs work. When you run a Java program, you are actually starting a JVM instance. That instance will have its own System properties. That is where you have to put your property. When you run the other program, that will have its own System properties. So, you cannot expect a property which you set in one JVM instance to be accessible from another JVM instance! You can access the System.getProperty(propertyKey) in all classes running in the same JVM instance. Hope you can understand!

这篇关于System.setProperty和System.getProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆