我正在尝试创建一个利用 Java Properties 类的 Eclipse Android 项目。对于该项目,我的 src 目录中有一个配置文本文件,其中包含键值对。我还有一个配置类,它包含一个属性对象,用于最初读取配置文件以及在整个执行过程中访问各种属性。但是,我在访问某些属性时遇到了一些错误。我想查看我正在生成的属性文件,以便我可以更轻松地进行调试。我该怎么做呢?
public static Properties prop;
static {
AssetManager assetManager = getApplicationContext().getAssets();
InputStream instream = assetManager.open("config");
readConfig(instream);
}
private static void readConfig(Inputstream instream) {
try {
String line = "";
BufferedReader read = new BufferedReader(instream);
while ((line = read.readLine()) != null) {
String[] split_line = line.split("=", 2);
prop.setProperty(split_line[0], split_line[1]);
}
prop.store(new FileOutputStream("config.properties"), "Default and local config files");
read.close();
}
catch (Exception e) {
Log.d("cool", "Failed to create properly initialize config class");
}
}
public static String getProperty (String propertyKey) {
try {
return prop.getProperty(propertyKey);
}
catch (Exception e) {
Log.d("cool", "Failed to access property");
return null;
}
}