tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvie Perrin <>
Subject Re: Create FileInputStream in servlet from remote file with accentuated character name
Date Fri, 18 Sep 2009 12:35:30 GMT

Thank you for your help and see inline the results of the test you suggest.
It shows that "sun.jnu.encoding" hasn't got the same value in standalone 
and servlet runs.

So, I change this property in the servlet test, by adding
in my Tomcat starting file and then I restart my Tomcat.

I verify that "sun.jnu.encoding" is now equals to UTF-8 in the output print.

But my issue is still here, ie. the FileNotFoundException.

Any other idea ?


Christopher Schultz a écrit :
> Hash: SHA1
> Sylvie,
> On 9/17/2009 9:12 AM, Sylvie Perrin wrote:
>> I have a shared directory on a windows system named SHAREDDIR and
>> containing one file named "fichié.txt"
>> I mount this shared directory on my Linux system with the following
>> command:
>>> mount -t cifs -o iocharset=utf8 //IpWindows/SHAREDDIR /home/me/mountDir/
>> In a standalone Java application running on my Linux system, I can
>> create a FileInputStream from the file located in the remote directory
>> like this:
>> String mountPath = "/home/me/mountDir";
>> File[] list = new File(mountPath).listFiles();
>> File file = list[0];
>> try {
>>    FileInputStream fStream = new FileInputStream(file);
>> }
>> catch (FileNotFoundException e) {
>>    e.printStackTrace();
>> }
> Can you have your standalone Java program print the following information:
> 1. The full path of the file
> 2. The values for these system properties:
>    a. file.encoding
>    b. sun.jnu.encoding
For Standalone Java program :
File full path = /home/me/mountDir/fichié.txt
file.encoding System property = UTF-8
sun.jnu.encoding System property = UTF-8

>> When I execute the same code in a servlet running on the same machine,
>> the call to FileInputStream constructor always throws a
>> FileNotFountException because it  doesn't recognize the "é" character in
>> the path of the file.
> Please post the above values within your servlet environment, too.
For Servlet program :
File full path = /home/me/mountDir/fichi��.txt
file.encoding System property = UTF-8
sun.jnu.encoding System property = ANSI_X3.4-1968

Note that my Firefox encoding display is set to UTF-8
> Are you sure that it's because of the é, or is it because the user that
> Tomcat is running under does not have permission to read that file?
> Under what user /is/ Tomcat running?
I am sure that it's not user permission issue because when I rename my 
file, I can execute my servlet and create my FileInputStream without any 
>> Since I don't know what the problem is I have had a hard time tracking
>> down a solution online. I especialy take care to follow all steps
>> described in the FAQ/CharacterEncoding parts of wiki. Here is my
>> configuration:
>> I set URIEncoding in my port 8080 connector to UTF-8 (I use this port to
>> execute my servlet)
>> <Connector port="8080" protocol="HTTP/1.1"
>>   connectionTimeout="20000"
>>   redirectPort="8443"
>>   URIEncoding="UTF-8"
>>   useBodyEncodingForURI="true" />
> None of these settings matter. These are only relevant for HTTP
> communication, and your code is not reading anything from the request.
>> I use a filter to set the default encoding to UTF-8 and my first line of
>> my doFilter method is
>> request.setCharacterEncoding("UTF-8");
> Your filter sets /what/ default encoding? What does it set it to?
> Setting the encoding of the request will not affect your code above.
>> I add in my servlet the set of content-type for responses to UTF-8 and
>> my first line of my doGet method is
>> response.setContentType("text/html;charset=UTF-8");
> This will also have no effect.
I agree with that, but I was so lost that I applied all "Character 
encoding tutorials" I have found !
>> My tomcat is started with CATALINA_OPTS=-Dfile.encoding=UTF-8
> Okay. Let's see what your command-line program reports for
> file.encoding, etc.
> - -chris
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla -
> iEYEARECAAYFAkqyZxQACgkQ9CaO5/Lv0PArBACdGM53y+0/2L1lkf3gvngXpnAz
> 8D8An3pjgMT4jBOk6jg+zRNEXGORzJ1G
> =v9Bf
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message