java:如何向属性文件添加值并在程序中访问它们
在我的eclipse项目中,我在许多java类文件、少数JSP和context.xml文件中都有ip地址字符串变量。我想创建一个kind.properties文件,并将这个ip地址声明为键值对,并从这个特定文件中的所有类进行访问。我如何实现这一点 问候java:如何向属性文件添加值并在程序中访问它们,java,Java,在我的eclipse项目中,我在许多java类文件、少数JSP和context.xml文件中都有ip地址字符串变量。我想创建一个kind.properties文件,并将这个ip地址声明为键值对,并从这个特定文件中的所有类进行访问。我如何实现这一点 问候 TT使用类似的方法: // Read properties file. Properties properties = new Properties(); try { properties.load(new FileInputStream
TT使用类似的方法:
// Read properties file.
Properties properties = new Properties();
try {
properties.load(new FileInputStream("filename.properties"));
String value = properties.getProperty("propertyKey");
} catch (IOException e) {
}
- 挽救
加载java.util.Properties.load(..)
Properties
是java SDK中java.util.*的一部分,“filename.Properties”
应该在类路径中(或者,给出文件的完整路径)。在您的情况下,propertyKey
将是ipAddress
,返回的值将是配置的IP地址