I am newbie in XML files operation. My program should do that when it is executed, it must generate random numbers and write to a XML file. Every time when I debug it in NetBeans IDE everything is okay, but when I try execute it in console with "Java -jar blablabla.jar" the XML files are not changing and I still see old values in XML files. Why is that happen? Why can IDE modify the values in XML while console cannot?
Here is my XML operations code block:
public class CreateXML {
public CreateXML(ArrayList<Integer> array,String name){
try{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
String path="file"+name+".xml";
File xmlfile=new File(path);
if(xmlfile.exists()){
xmlfile.delete();
System.out.println("There was this file and it is deleted.");
}
Document doc=db.newDocument();
Element rootElement=doc.createElement("numberList");
doc.appendChild(rootElement);
for (int i = 0; i < array.size(); i++) {
Element staff=doc.createElement("number");
rootElement.appendChild(staff);
Attr attr=doc.createAttribute("id");
attr.setValue(Integer.toString(i));
staff.setAttributeNode(attr);
staff.setTextContent(Integer.toString(array.get(i)));
}
TransformerFactory tf=TransformerFactory.newInstance();
Transformer t=tf.newTransformer();
DOMSource source=new DOMSource(doc);
StreamResult result=new StreamResult(xmlfile);
t.transform(source, result);
}catch(Exception e){
e.printStackTrace();
}
}
}