delphi - Delphi FMX (Android) - 如何在没有提取的情况下读取 zip 流中的文本文件?
问题描述
是否可以从 zip 文件中读取文件而不提取文件?我想从备忘录行中的压缩文件(作为 android 资产)中读取文本文件。
ZipFile := TZipFile.Create; //Zipfile: TZipFile
try
ZipFile.Open('C:\Path\to\file.zip', zmRead);
for I := 0 to ZipFile.FileCount - 1 do
begin
if ZipFile.FileNames[I]='A1.txt' then //S: string
//My problem is here ? How load A1.txt to memo lines?
Memo1.Lines.Add(S);
end;
ZipFile.Close;
finally
ZipFile.Free;
end;
解决方案
TZipFile
Read()
具有允许您获取TBytes
完整解压缩文件或TStream
动态读取解压缩字节的公共方法。您可以根据需要使用这些字节写入TMemo
。
例如,使用 a TStream
,您可以将文件中的字节读入本地缓冲区,直到遇到换行符,然后将缓冲区添加到TMemo
并清除缓冲区,重复直到到达TStream
.
请注意,在任何一种情况下,您都将访问文本文件的原始字节,而需要 Unicode 字符串,因此您必须根据文本文件的实际编码TMemo
将字节转换为 Unicode,例如 with 。SysUtils.TEncoding
例如,TEncoding.UTF8
如果文本文件是 UTF-8 编码,则使用。 TEncoding
具有GetString()
将TBytes
数据转换为UnicodeString
.
推荐阅读
- javascript - 是否可以将 blob 转换为 pptx?
- docker - 在自定义 GitHub 操作中挂载运行 docker-in-docker 容器的文件夹
- .net - 即使工作正常,Visio VSTO 中的 .NET OpenFileDialog FileNotFoundException
- server - 有没有办法在发布之前以服务器模式查看 Tableau 仪表板/工作表?
- php - API POST 请求返回 HTML 而不是 JSON 并且没有进入我的 HTML 元素
- c# - IOCPT/IOCP - 它只存在于 Windows 中吗?
- raku - 在 termux/android 上安装 Rakudo
- cmake - CPPCheck:本地头文件中的错误未被捕获
- go - 在 Gitlab 上使用私有 go 模块作为导入:“未知修订版”
- file - 如何在 OneDrive、SharePoint 或其他合适的平台中创建计划文件结构