开发者

How to read Hebrew text using System.IO.FileStream?

开发者 https://www.devze.com 2022-12-23 15:41 出处:网络
Am I missing something or does System.IO.FileStream not read Unicode text files containing Hebrew? public TextReader CSVReader(Stream s, Encoding enc)

Am I missing something or does System.IO.FileStream not read Unicode text files containing Hebrew?

    public TextReader CSVReader(Stream s, Encoding enc) 
    {

        this.stream = s;
        if (!s.CanRead) 
        {
            throw new CSVReaderException("Could not read the given CSV stream!");
        }
        reader = (enc != null) ? new StreamReader(s, enc) : new S开发者_JAVA技巧treamReader(s);
    }

Thanks Jonathan


The FileStream is nothing but a byte stream, which is language/charset agnostic. You need an encoding to convert bytes into characters (including Hebrew) and back.

There are several classes to help you with that, the most important being System.Text.Encoding and System.IO.StreamReader and System.IO.StreamWriter.


The stream might be closed.

From msdn on CanRead:

If a class derived from Stream does not support reading, calls to the Read, ReadByte, and BeginRead methods throw a NotSupportedException.

If the stream is closed, this property returns false.


I'd wager that you're simply not using the right encoding. Chances are you're passing in Encoding.Default or Encoding.ASCII when you should actually be passing Encoding.UTF8 (most common) or Encoding.Unicode to that method.

If you're sure that you're using the right encoding, post the full code and an example of the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消