Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file.encoding System Property

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the jdk documentation, the "file.encoding" system property is mentioned. However, where can I find the related documentation about this property? I am not trying ask here what this property means. Instead, I just want to know where is its documentation. I come across this term many times did some search but just could not find out its documentation. Is it some unofficial property that we should not bother with?
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Java Tutorial :


Remember that FileReader and FileWriter read and write 16-bit characters. However, most native file systems are based on 8-bit bytes. These streams encode the characters as they operate according to the default character-encoding scheme. You can find out the default character-encoding by using System.getProperty("file.encoding"). To specify an encoding other than the default, you should construct an OutputStreamWriter on a FileOutputStream and specify the encoding.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file.encoding property really isn't properly documented. Yeah, it's mentioned in the tutorial, but it really should be documented in the API under System.getProperties() (like all standard properties are documented) - and it isn't. Here is the relevant RFE. Note that the problem is effectively solved now in JDK 5 using java.nio.charset.Charset.defaultCharset().name(). Prior to JDK 5, you can use new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding(). Which is slightly convoluted, but it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic