这里是您可以使用属性文件在您的项目的完整解决方案。
1创建Android专案
2编辑该文件夹的资产名为app.properties文件,并在要使用例如,作为
test=success
和保存文件的属性写
3写这个方法在你的活动课
private Properties loadPropties() throws IOException {
String[] fileList = { "app.properties" };
Properties prop = new Properties();
for (int i = fileList.length - 1; i >= 0; i--) {
String file = fileList[i];
try {
InputStream fileStream = getAssets().open(file);
prop.load(fileStream);
fileStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "Ignoring missing property file " + file);
}
}
return prop;
}
4随着onCreate方法写一些这样的事
Properties prop = null;
try {
prop = loadPropties();
} catch (IOException e) {
Log.e(TAG, "Exception", e);
}
Toast.makeText(getApplicationContext(), "Result " + prop.getProperty("test"),
Toast.LENGTH_LONG).show();
5中添加必要的进口
希望这有助于:)
此外,它帮助谁面临着同样的问题其他人。通过查看接受的答案。您可以通过点击答案右侧的支票图片来接受答案。 – Javanator 2012-04-21 05:15:52
如果您对所有给定的答案不满意。即使那样,你一定是找到了你自己的解决方案。张贴并接受你的答案。但要尽量让问题与接受的答案结合起来。我知道这一切都很明显。但有些时候它更好的是详细:) – Javanator 2012-04-21 05:19:38