• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sax2 Xerces parser encoding problem  RSS feed

 
sergejs artemjevs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone! I am new to this forum as a poster(not new as a reader)

I've got a problem with xml sax2 xerces parser. Googling hasn't solved the problem so i decided to try some luck here...

I've got a Sax parser class which is used in Swing application and in web project deployed to a GlassFish.The class parses xml files. It works perfectly in Netbeans IDE Swing application(in the IDE) and web project.But when I Clean and Build swing app into a one .jar it doesn't recognize anymore symbols like ī, ķ, ļ, ā (foreign language symbols) from xml file.The same problem happens if I compile and run my sax parser class through cmd. No exception is thrown - just foreign symbols not recognized.

xml header is: <?xml version="1.0" encoding="UTF-8" ?>

Had the same problem in web project - sorted using Glassfish configuration.

The question is how to solve this problem in swing app so i can pack the project into a jar and run it without encoding problems?

here is a peace of code:
is.setEncoding("UTF-8") -> doesn't change anything



 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

The way you create a FileReader, it uses the system's encoding. You need to specify its encoding as well, with a workaround:
You need to use FileInputStream + InputStreamReader because FileReader doesn't allow you to specify the encoding (which I think is a flaw in the API).
 
sergejs artemjevs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Welcome to the Ranch!

The way you create a FileReader, it uses the system's encoding. You need to specify its encoding as well, with a workaround:
You need to use FileInputStream + InputStreamReader because FileReader doesn't allow you to specify the encoding (which I think is a flaw in the API).


That works, thank you!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!