0
我不明白爲什麼我得到這個錯誤,我試圖寫入一個文件,而不是從它讀取。起初我得到一個錯誤,因爲我沒有把一個jar放在libs文件夾中,現在我得到這個錯誤。這裏是我的代碼,將不勝感激! :)Android上的JDom:打開跟蹤文件錯誤:沒有這樣的文件或目錄
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
writeXML();
}
private void writeXML() {
try{
Document doc = new Document();
Element theRoot = new Element("tvshows");
doc.setRootElement(theRoot);
Element show = new Element("show");
Element name = new Element("show");
name.setAttribute("show_id", "show_001");
name.addContent(new Text("Life On mars"));
Element network = new Element("network");
network.setAttribute("country", "US");
network.addContent(new Text("ABC"));
show.addContent(name);
show.addContent(network);
theRoot.addContent(show);
// - -
Element show2 = new Element("show");
Element name2 = new Element("show");
name2.setAttribute("show_id", "show_002");
name2.addContent(new Text("Life On mars"));
Element network2 = new Element("network");
network2.setAttribute("country", "US");
network2.addContent(new Text("ABC"));
show2.addContent(name2);
show2.addContent(network2);
theRoot.addContent(show2);
XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(doc, new FileOutputStream(new File("C:\\Users\\jmckay\\Desktop\\jdomMade.xml")));
TextView tv = (TextView)findViewById(R.id.text);
tv.setText("done");
}catch(Exception e){
e.printStackTrace();
}
}
謝謝,我會試試看! – Cj1m
工作很棒WOOHOO非常感謝! – Cj1m
我還有一個問題,我現在想從文件中讀取。什麼目錄是我的XML在我需要這個文件readDoc = builder.build(新的文件(目錄)); – Cj1m