I have a problem that output string must be utf8-formatted, I am writing currently ansi string to zip file without problems like this:
StreamReader tr = new StreamReader( "myutf8-file.xml");
String myfilecontent = tr.ReadToEnd();
ZipFile zip = new ZipFile());
zip.AddFileFromString("my.xml", "", myfilecontent );
How to force string (my.xml file content) to be UTF8.
Don't use the deprecated AddFileFromString
method. Use AddEntry(string, string, string, Encoding)
instead:
zip.AddEntry("my.xml", "", myfilecontent, Encoding.UTF8);
If you're actually reading a UTF-8 text file to start with though, why not just open the stream and pass that into AddEntry
? There's no need to decode from UTF-8 and then re-encode...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.