在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
新版本Delphi中自带的Zip单元System.Zip使用很方便,但是在压缩文件中包含中文路径或文件名时解压后是乱码,这一点儿确实挺烦人。 之所以会出现乱码是由以下两个函数造成的: 1 function TZipFile.TBytesToString(B: TBytes): string; 2 var 3 E: TEncoding; 4 begin 5 if FUTF8Support then 6 E := TEncoding.GetEncoding(65001) 7 else 8 E := TEncoding.GetEncoding(437); 9 try 10 Result := E.GetString(B); 11 finally 12 E.Free; 13 end; 14 end; 1 function TZipFile.StringToTBytes(S: string): TBytes; 2 var 3 E: TEncoding; 4 begin 5 if FUTF8Support then 6 E := TEncoding.GetEncoding(65001) 7 else 8 E := TEncoding.GetEncoding(437); 9 try 10 Result := E.GetBytes(S); 11 finally 12 E.Free; 13 end; 14 end; 将上面红色标记的代码中CodePage修改为936即可解决,或者直接替换掉这两个函数: 1 function TZipFile.TBytesToString(B: TBytes): string; 2 begin 3 if FUTF8Support then 4 Result := TEncoding.UTF8.GetString(B) 5 else 6 Result := TEncoding.Default.GetString(B); 7 end; 1 function TZipFile.StringToTBytes(S: string): TBytes; 2 begin 3 if FUTF8Support then 4 Result := TEncoding.UTF8.GetBytes(S) 5 else 6 Result := TEncoding.Default.GetBytes(S); 7 end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论