java - Xerces Sax2 parser encoding problem -
i've got sax parser class used in swing application , in web project deployed glassfish.
the class parses xml files. works in netbeans ide swing application(in ide) , web project.
but when clean , build swing app 1 .jar doesn't recognize anymore symbols ī, ķ, ļ, ā xml file.
the same problem happens if compile , run through cmd.
had same problem in web project - sorted using glassfish configuration.
the question how solve problem in swing app?
here peace of code:
public void parsedocument(string filepath) { try { xmlreader xr = xmlreaderfactory.createxmlreader(); xr.setcontenthandler(this); inputsource = new inputsource(new filereader(filepath)); is.setencoding("utf-8"); xr.parse(is); }catch(saxexception se) { se.printstacktrace(); }catch (ioexception ie) { ie.printstacktrace(); } }
no setencoding() method.
you have answered question, other way deal explicitly set conversion when open file.
public void parsedocument(string filepath) { try { xmlreader xr = xmlreaderfactory.createxmlreader(); xr.setcontenthandler(this); reader reader = new inputstreamreader(new fileinputstream(filepath); inputsource = new inputsource(reader, "utf-8"); is.setencoding("utf-8"); xr.parse(is); }catch(saxexception se) { se.printstacktrace(); }catch (ioexception ie) { ie.printstacktrace(); } }
the big difference between this, , solution in question using inputstreamreader on top of fileinputstream. according javadoc filereader, opens file in "default character set", why solution works, since changing default character set. can explicitly character set want open file in, need use combination of inputstreamreader , fileinputstream.
Comments
Post a Comment