我在以下路徑「/res/xml/keywords.xml」中有一個xml文件。 它具有以下內容如何將數據追加到Android中的xml內容中
<words>
hdhsd
</words>
我用Java代碼:
OutputStreamWriter out=new OutputStreamWriter(openFileOutput("keywords.xml", MODE_APPEND));
out.write("hello");
out.close();
單詞「hello」並沒有被附加到文件中。爲什麼會發生?
感謝您的回答。您的意思是我將在以下路徑中使用我的xml文件「C:\ Documents and Settings \ Desktop \ D \ Temp \ Android \ Books \ Beginning Android 3 \ Applications \ AndroidApplication2」? –
我使用下面的代碼在xml文件中寫入數據 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File(「C:\\ Documents and Settings \\ Desktop \\ D \\ Temp \\ Android \\ Books \\ Beginning Android 3 \\ Applications \\ AndroidApplication2 \\ keywords.xml 「)); Node node = doc.getElementsByTagName(「words」)。item(0); org.w3c.dom.Element newelmnt = doc.createElement(「word」); newelmnt.appendChild(doc.createTextNode(「moijjjjjjjj」)); node.appendChild(newelmnt); –
但IOException已經通過。這裏的問題在哪裏? –