Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

PB read/write avec JEditorPane et HTML

2 réponses
Avatar
Silicon
Salut,
j'ai un probl=E8me avec le r=E9sultat des m=E9thodes read(Reader, Object)
et write(Writer) de JEditorPane (JTextComponent). Dans un premier
temps, je lis un fichier HTML avec la m=E9thode read. Ensuite, je cr=E9e
un nouveau fichier HTML avec la m=E9thode write. Le fichier obtenu ne
contient pas les derni=E8res balises HTML !! Mon fichier origine est
constitu=E9 d'un simple tableau et le fichier r=E9sultat n'a pas les
dernier <TD> ni les balises </table> </body> et </html> !!
Le 'contentType' de mon JEditorPane est =E0 "text/html" et j'utilise le
code suivant:

[code]
// Cr=E9ation d'un JEditorPane
JEditorPane textComponent =3D new JEditorPane();

// Lecture du fichier Toto.html
Reader reader =3D new InputStreamReader(new FileInputStream("Toto.html");
textComponent.read(reader,"text/html");

// Ecriture du fichier TotoSortie.html
Writer writer =3D new FileWriter("TotoSortie.html");
textComponent.write(writer);
[/code]


Quelqu'un peut-il me dire o=F9 est mon erreur ? S'agit-il d'un bug ?
Pour info, j'utilise la JDK1.5

Merci d'avance pour vos r=E9ponses.

-Silicon-

2 réponses

Avatar
Hervé AGNOUX
Silicon wrote:


// Ecriture du fichier TotoSortie.html
Writer writer = new FileWriter("TotoSortie.html");
textComponent.write(writer);
[/code]



Est-ce que tu fais writer.flush() et writer.close() après ?

--
Hervé AGNOUX
http://www.diaam-informatique.com

Avatar
Silicon
Merci Hervé,
ça fonctionne.
Je n'avais même pas essayé avant car j'étais persuadé que la
méthode write du JTextComponent s'en chargait.... Visiblement j'avais
tord.

Merci pour ton aide.