回写xml
一个xml文件,读完后,重新设置,如何把数值写回到文件中。
我的代码如下,总是在删除的时候出错,请大家指点。
或者给出相应的写代码。谢谢了
public void WriteXml() throws IOException{
if(xmlFile.equals(""))return;
if(getModified()==false)return;
KXmlSerializer xmlSerial = new KXmlSerializer ();
FileConnection fc=null;
fc=(FileConnection)Connector.open(xmlFile);
try{
fc.delete();
}
catch(Exception e){
System.out.println("Error:"+e.getClass().toString());
}
fc.create();
// xmlSerial.setOutput(new OutputStreamWriter(bos));
// OutputStreamWriter osw=new OutputStreamWriter(fc.openOutputStream(),"utf-8");
// fc.truncate(fc.fileSize());
OutputStream out=fc.openOutputStream();
xmlSerial.setOutput(out, xmlDoc.getEncoding());
xmlDoc.write(xmlSerial);
xmlSerial.flush();
out.flush();
out.close();
this.setModified(false);
}