Encoding Headaches... and JNI

Hi people,

I am having trouble with an encoding issue. Through JNI (java native interface), I receive a const char* with the path of a file, which I suppose to open on the c++ side. JNI only returns UTF chars and everything works wonderful when the path doesn't have other type of it. However, when Java passes "D:\Cla\Clã - ponto zero.mp3", I receive "D:\Cla\Clã - ponto zero.mp3", and, of course, the library says the file is missing.

How should I proceed? Does JNI return chars in other encoding? Should I convert the UTF to ISO-8859-1? How can I do this in c++?

Many thanks in advance,
José Treta
I'm not sure exactly how your first string got changed to the second, but what I can tell you is this:

I presume you are working on Windows (since on Linux a UTF-8 string works for filenames).

Java encodes strings as a special form of UTF-8 (which allows encoding zero specially).

If your UTF-8 string has any characters > 0x7F, you'll need to decode it into a wstring, which you can then pass to windows file functions to open the file.

Best to avoid files with funny names.

Hope this helps.
humm... and how can I decode it into a wstring?? I am not really experienced on c++... I also take the opportunity to learn a little bit and ask the difference between a wstring and a string.

Thanks for your help!
You can get the algorithms here:
http://www.cplusplus.com/forum/beginner/7233/#msg33495

Hope this helps.
Thanks Duoas!!

I just resolved the problem thanks to your advices. I'm also thankful for your quickness.
Now I can go sleep well eheh...
Topic archived. No new replies allowed.