User Guide

Table Of Contents
Handling data in ColdFusion MX 419
File data
You use the
cffile tag to write to and read from text files. By default, the cffile tag assumes
that the text that you are reading, writing, copying, moving, or appending is in the JVM default
file character encoding, which is typically the system default character encoding. For
cffile
action="Read"
, ColdFusion MX also checks for a byte order mark (BOM) at the start of the file;
if there is one, it uses the character encoding that the BOM specifies.
Note: To specify the JVM default file character encoding, use the -Dfile.encoding= switch in the
JVM Arguments field on the Java and JVM page in the ColdFusion MX Administrator.
Problems can arise if the file character encoding does not correspond to JVM character encoding,
particularly if the number of bytes used for characters in one encoding does not match the
number of bytes used for characters in the other encoding.
For example, assume that the JVM default file character encoding is ISO 8859-1, which uses a
single byte for each character, and the file uses Shift-JIS, which uses a two-byte representation for
many characters. When reading the file, the
cffile tag treats each byte as an ISO 8859-1
character, and converts it into its corresponding two-byte Unicode representation. Because the
characters are in Shift-JIS, the conversion corrupts the data, converting each two-byte Shift-JIS
character into two Unicode characters.
To enable the
cffile tag to correctly read and write text that is not encoded in the JVM default
character encoding, you can pass the
charset attribute to it. Specify as a value the character
encoding of the data to read or write, as the following example shows:
<cffile action="read"
charset="EUC-KR"
file = "c:\web\message.txt"
variable = "Message" >
Databases
ColdFusion applications access databases using drivers for each of the supported database types.
The conversion of client native language data types to SQL data types is transparent and is done
by the driver managers, database client, or server. For example, the character data (SQL CHAR,
VARCHAR) you use with JDBC API is represented using Unicode-encoded strings.
Database administrators configure data sources and usually are required to specify the character
encodings for character column data. Many of the major vendors, such as Oracle, Sybase, and
Informix, support storing character data in many character encodings, including Unicode UTF-8
and UTF-16.
The database drivers supplied with ColdFusion MX correctly handle data conversions from the
database native format to the ColdFusion Unicode format. You should not have to perform any
additional processing to access databases. However, you should always check with your database
administrator to determine how your database supports different character encodings.