Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

determine encoding at runtime  RSS feed

 
Ioana Danescu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I need to find out the encoding (ANSI, Unicode, UTF-8 etc.) of a file
at runtime.

Does anybody know some Java API that helps me to do this?

Thanks and regards,
Ioana
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking for a program that can read a file and determine what encoding was used to write it. I don't think there is one.
There was an early post on this same topic.
 
Ioana Danescu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is what I was asking for.
I need to be able to upload a file into an application that supports 7 languages (at this moment, in the future more). The text in the file can be written in any language. For instance, I have to following string (having diacritics) in the file "Zeitschrift f�r anorganische und allgemeine Chemie".
If I read it using
new BufferedReader (new InputStreamReader (in, "UTF8"))
and the file is not created using UTF8 encoding I get an error.
I can not tell to the customers they have to create the file using UTF-8 encoding because when opening such a file in Excel, the letters with diacritics are not displayed correctly.

If this file is created using ANSI encoding, then I can read it using

new BufferedReader (new InputStreamReader (in, "ISO8859_1")), but this won't work for other languages (like Chinese) that I need to support.

This is why I was doubting whether there is a possibility to know which encoding was used when creating a file.

But thanks anyway!
Ioana
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!