Skip to main content
Participant
February 23, 2011
Question

Coldfusion can't read French accents from text file

  • February 23, 2011
  • 1 reply
  • 3365 views

Hi all,

I am trying to read some french accents from a text file and i am getting some weird characters from the french accents. I tried applying some encoding thing, but nothing changed. I post below some details of my problem,would be great if you could help me out of it. thanks

I have a text file content as follows:

fileName: msg123.txt

Transfert : Aéroport-Hôtel Paradis
Siège enfant/bébé
PRI en Voiture Privée le 06DEC10

when i use coldfusion to read the file the output is like that:

Transfert : A�roport-H�tel Paradis

Si�ge enfant/b�b�

PRI en Voiture Priv�e le 06DEC10

my CFM who reads the text file looks like that:

fileName: read.cfm

<!--- READS ALL TEXT FILES --->
<cfset pathDirectory = ExpandPath( "./file" ) />

<cfdirectory action="list" directory="#pathDirectory#" filter="*.txt"  name="filename"/>


<cfloop query="filename">

     <cfset FilePath = "#pathDirectory#/#name#">
    
     <cfscript>
          // Define the file to read, use forward slashes only
          FileName="#FilePath#";
          // Initilize Java File IO
          FileIOClass=createObject("java","java.io.FileReader");
          FileIO=FileIOClass.init(FileName);
          LineIOClass=createObject("java","java.io.BufferedReader" );
          LineIO=LineIOClass.init(FileIO);
     </cfscript>

....

May you please advice me how should i do it correctly?

Regards

Message was edited by: diditin

This topic has been closed for replies.

1 reply

Inspiring
February 23, 2011

On 2/23/2011 1:47 PM, diditin said:

I have a text file with content as follows:

what version of cf (mx & newer, cf defaults to utf-8 encoding)? what encoding is

the text file?

if the file is not utf-8 encoded (guess latin-1??) then try

// Initilize Java File IO

btw if you're on cf8 & above you could simply use cfloop w/the file option. i

think it gives about the same performance as the java IO bits.

diditinAuthor
Participant
February 23, 2011

Thanks for your reply Paul.

In fact, i receive a pdf as attachment from a mail, open the pdf, save it as text. then i used my read.cfm to read the text file i just got. So i don't really know what the encoding of the text file. Why I need to do it like that? it is to be able to keep the line by line format. else if i read directly the pdf, it will give me a bundle of data without any newline.

I am using CF8.

Try what exactly? tag cfprocessingdirective?

Inspiring
February 23, 2011

On 2/23/2011 7:25 PM, diditin said:

Try what exactly? tag cfprocessingdirective?

yeah, the forums swallowed the example tag, try "ISO-8859-1" as the pageEncoding

value because i think the reader defaults to ANSI or latin-1 when it writes out

text like that.