Olá pessoal!
Estou com dificuldades de resolver um problema com o charset dos arquivos HTML locais em meu pc, seguinte: abro um arquivo HTML por uma aplicação que faz a leitura deste arquivo em um JEditorPane e na leitura do arquivo local sempre encontro a exceção ChangedCharsetEsception e lendo o mesmo arquivo via URL, ou seja, pela internet, a exceção não ocorre.
Tenho rotinas diferentes para ler o arquivo local e a página e nas duas dou um set na propriedade “IgnoreCharset” do JEditorPane para true.
Já procurei em diversos fóruns e até agora não encontrei uma solução para meu problema, se alguém puder me ajudar fico muito grato.
Ai vai o trecho de cod para abrir o arquivo localmente:
jEditorPane1.setEditable(false);
jEditorPane1.setContentType("text/html");
htmlKit = jEditorPane1.getEditorKitForContentType("text/html");
doc = (HTMLDocument) htmlKit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
jEditorPane1.setEditorKit(htmlKit);
Reader rdrIn = new FileReader(file.getAbsolutePath());
jEditorPane1.setPage(file.toURL().toString());
jEditorPane1.read(rdrIn, doc);
E o seguinte abre uma página qquer da web:
jEditorPane1.setEditable(false);
jEditorPane1.setContentType("text/html");
htmlKit = jEditorPane1.getEditorKitForContentType("text/html");
doc = (HTMLDocument) htmlKit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
jEditorPane1.setEditorKit(htmlKit);
u = new URL(txtURL.getText());
in = u.openStream();
jEditorPane1.read(in, doc);
Guilherme.