publicvoidSerialize(Clientecli){XStreamSerialize=newXStream();try{FileOutputStreamfs=newFileOutputStream("Cliente.xml");Serialize.toXML(cli,fs);}catch(FileNotFoundExceptione1){e1.printStackTrace();}}publicvoidDesSerialize(Clientecli)throwsFileNotFoundException,IOException{XStreamDesSerialize=newXStream(newDomDriver());Clientee=newCliente();try{FileInputStreamfis=newFileInputStream("Cliente.xml");DesSerialize.fromXML(fis,e);//print the data from the object that has been readSystem.out.println(e.toString());}catch(FileNotFoundExceptionex){ex.printStackTrace();}
e uma coisa ele so faz de um unico cliente quando tento fazer de outro ele faz por cima do que ja estava quero que faça abaixo do anterior no mesmo arquivo alguem tem alguma ideia ???
peczenyj
Ora. vc esta mandando o arquivo.xml ser sobreescrito a cada vez que vc quiser escrever no mesmo.
Se vc quer ter uma lista de clientes vc pode fazer duas coisas:
abrir o arquivo.xml no modo append (passe true como segundo parametro do contrutor do FileOutputStream
serializar um array ou lista de clientes.
fabiodurgante
FileOutputStream fs = new FileOutputStream(“Cliente.xml”,true);
assim da erro cara nao sei o porque
[Fatal Error] :7:12: The markup in the document following the root element must be well-formed.
:12: The markup in the document following the root element must be well-formed.com.thoughtworks.xstream.io.StreamException: : The markup in the document following the root element must be well-formed.at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:86)at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:70)at com.thoughtworks.xstream.XStream.fromXML(XStream.java:891)at ClienteDao.DesSerialize(ClienteDao.java:69)
fabiodurgante
quando eu uso a funcao
publicvoidDesSerialize()throwsFileNotFoundException,IOException{XStreamDesSerialize=newXStream(newDomDriver());Clientecli=newCliente();try{FileInputStreamfis=newFileInputStream("Cliente.xml");DesSerialize.fromXML(fis,cli);//print the data from the object that has been readSystem.out.println(cli.toString());}catch(FileNotFoundExceptionex){ex.printStackTrace();}}
ela me retorna
Cliente@1ef9157
e teria que retorna id nome cpf
alguem sabe porque isso ???
M
marcobiscaro2112
Ele retorna um objeto do tipo Cliente. Tente fazer isso:
// após carregar o objeto:System.out.prinln(cli.getId());System.out.prinln(cli.getNome());System.out.prinln(cli.getCpf());// esses getters são supostos. Podem ser apresentados de forma diferente
fabiodurgante
exatamente isso entendi o esquema ele carrega tudo mas em CLIENTE e nao é possivel larga direto o cliente
tem que ser um por 1 ok valeu cara
quando eu coloco true a primeira vez da certo depois quando ele vai escrever e nao sobrescrever ocorre esse erro ai
sem o true funciona so que fica sempre sobrescrevendo e eu nao quero isso quero poder ter 4 5 6 assim por diante cliente no XML
Fatal Error] :7:12: The markup in the document following the root element must be well-formed.com.thoughtworks.xstream.io.StreamException: : The markup in the document following the root element must be well-formed.at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:86)at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:70)at com.thoughtworks.xstream.XStream.fromXML(XStream.java:891)