Code: Select all
wxString testStr(wxT("abcdêü"));
wxString utf8Str = testStr.ToUTF8();
wxFile uft8File;
wxString filePath = wxGetUserHome() + wxT("\\Desktop\\uft8File.txt");
// write file
bool isOk = uft8File.Create(filePath, true);
isOk &= uft8File.Open(filePath, wxFile::read_write);
wxUint8 strLen = utf8Str.Length(); // 8 ?!?
uft8File.Write(&strLen, 1);
uft8File.Write(utf8Str); // 12 bytes are written
uft8File.Close();
// read file
isOk &= uft8File.Open(filePath, wxFile::read);
char buf[20];
uft8File.Read(buf, 1);
strLen = buf[0];
uft8File.Read(buf, strLen);
wxString fromFile(buf[0], file.Length());
wxString fromUtf8 = wxString::FromUTF8(fromFile);
uft8File.Close();