是否可以從SD卡加載strings.xml而不是應用程序res/values/...在網絡上搜索,但沒有找到任何教程。我的想法是將xml下載到sd卡,然後將字符串元素保存到數組中。從SD卡加載strings.xml到應用程序android
public void stringsxml(){
File file = new File(Environment.getExternalStorageDirectory()
+ ".strings.xml");
StringBuilder contents = new StringBuilder();
try {
//use buffering, reading one line at a time
//FileReader always assumes default encoding is OK!
BufferedReader input = new BufferedReader(new FileReader(file));
try {
String line = null; //not declared within while loop
/*
* readLine is a bit quirky :
* it returns the content of a line MINUS the newline.
* it returns null only for the END of the stream.
* it returns an empty String if two newlines appear in a row.
*/
while ((line = input.readLine()) != null){
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
}
finally {
input.close();
}
}
catch (IOException ex){
ex.printStackTrace();
}
String data= contents.toString();
}
因此而不是使用strings.xml中,我們可以存儲的語言爲.sqllite數據庫和服務器 – Dimitri
是更新數據庫,但你不能把它的資源。 – Szymon