|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Bannato
Iscritto dal: Oct 2007
Messaggi: 452
|
[JAVA/XML] Problema XML serializer... stampa il risultato su schermo, ma non su file!
Ciao a tutti,
ho un grande problema...magari sarà una cavolata, ma sto impazzendo! ![]() ho questo metodo... public void serialize(String file) throws IOException { FileWriter fw; fw=new FileWriter(file); BufferedWriter bw; bw=new BufferedWriter (fw); OutputFormat format = new OutputFormat("XML",null,true); format.setIndent(1); format.setIndenting(true); format.setDoctype(null,"DTD/example.dtd"); ser = new XMLSerializer(format); ser.setOutputCharStream(bw); ser.setOutputByteStream(System.out); ser.serialize(document); bw.flush(); bw.close(); } ...il problema è che ser.setOutputByteStream(System.out) mi stampa nella console il risultato esatto XML che dovrebbe mettermi nel file. ser.setOutputCharStream(bw) invece non scrive su file!...cioè, mi crea il file ma è vuoto!!! |
![]() |
![]() |
![]() |
#2 | |
Member
Iscritto dal: Jul 2005
Messaggi: 291
|
Quote:
Codice:
public void serialize(String file) throws IOException { FileWriter fw; fw=new FileWriter(file); FileOutputStream fos=new FileOutputStream(file); PrintStream ps=new PrintStream(fos); PrintStream out=System.out; System.setOut(ps); BufferedWriter bw; bw=new BufferedWriter (fw); OutputFormat format = new OutputFormat("XML",null,true); format.setIndent(1); format.setIndenting(true); format.setDoctype(null,"DTD/example.dtd"); ser = new XMLSerializer(format); ser.setOutputCharStream(bw); ser.setOutputByteStream(System.out); ser.serialize(document); bw.flush(); bw.close(); System.setOut(out); }
__________________
CPU: Intel Core 2 Quad Q6600 - Mobo: Asus P5E - RAM:4x2GB DDR2 - sk video: Power Color ATI Radeon HD3870 - HD:Western Digital 750GB |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 14:55.