permaculture playing cards*
The moose likes Java in General and the fly likes file.encoding System Property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "file.encoding System Property" Watch "file.encoding System Property" New topic
Author

file.encoding System Property

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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

Joined: Sep 28, 2005
Posts: 225
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.


Regards,<br />Seb<br /> <br />SCJP 1.4
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
Consider Paul's rocket mass heater.
 
subject: file.encoding System Property