using (var fileStream = File.OpenRead( filePath ) )
using (var bodyStream = new ZlibStream( fileStream, CompressionMode.Decompress))
using (var bodyReader = new BinaryReader(bodyStream))
{
fileStream.Seek(header.FileTablePosition + 8, SeekOrigin.Begin);
for (int i = 0; i < header.FileCount; i++)
{
var fileName = string.Empty;
char currentChar;
while ((currentChar = (char)bodyReader.ReadByte()) != 0)
{
fileName += currentChar;
}
}
.
.
.
}
위의 코드는 윈도우에서 압축파일을 BinaryReader의 ReadByte()를 이용해 byte단위로 읽어 와서 char형으로 변환하고
그걸 합해서 file이름으로 가져오는 부분인데요. 이걸 실행하면 파일이름이 한글로 되어 있으면 깨져 나옵니다. currentChar를 누적하니까
당연한거 같기도 합니다.
일단 BinaryReader(bodyStream)의 인코딩 옵션을 줘봤는데 안되더군요. 뭐 당연한거 같습니다만.
그리고 최종 fileName값의 인코딩 변환
Encoding utf8 = Encoding.UTF8;
byte[] utf8Bytes = utf8.GetBytes(fileName);
Han_FileName = utf8.GetString(utf8Bytes);
이렇게 수정해 디버그 상태에서 값을 봤는데 안되내요.
저 부분을 어떻게 수정하면 한글 파일이름을 인식하게 할 수 있을까요?
[최초 등록일: ]
[최종 수정일: 12/26/2022]