我对java完全是个新手。我想知道proto.properties文件在编程中的用途。任何关于这方面的细节都是值得感谢的。
向David致敬
发布于 2015-11-16 12:05:32
属性文件是使用两个参数存储属性的文件,一个称为键,这是变量名,另一个是您分配给键的值。
请记住,保存的所有值都是字符串
属性文件看起来像这样
# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
# The key and element characters #, !, =, and : are written with
# a preceding backslash to ensure that they are properly loaded.
website = http\://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
Wikipedia!
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces"
# Unicode
tab : \u0009发布于 2015-11-16 12:49:38
通常,Java属性文件用于存储项目配置数据或设置。
请参见下面的示例如何在Java中写入属性文件
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class App {
public static void main(String[] args) {
Properties prop = new Properties();
OutputStream output = null;
try {
output = new FileOutputStream("config.properties");
// set the properties value
prop.setProperty("database", "AIXDB");
prop.setProperty("dbuser", "mukesh");
prop.setProperty("dbpassword", "password");
// save properties to project root folder
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
**Output**
config.properties
dbpassword=password
database=AIXDB
dbuser=mukesh发布于 2015-11-16 13:01:31
属性是作为键/值对管理的配置值。在每一对中,键和值都是字符串值。键标识并用于检索值,就像变量名用于检索变量的值一样。
要管理属性,请创建java.util.Properties的实例。此类提供了用于以下操作的方法:
继承的一些方法
有关更多详细信息,请访问Java文档链接。Java Doc
https://stackoverflow.com/questions/33728264
复制相似问题