Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

determine encoding at runtime

 
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
 
Master Rancher
Posts: 3921
36
  • 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
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic