C# - Check if File is Text Based

后端 未结 6 791
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 09:19

How can I test whether a file that I\'m opening in C# using FileStream is a \"text type\" file? I would like my program to open any file that is text based, for example, .t

6条回答
  •  无人及你
    2020-11-29 10:08

    I guess you could just check through the first 1000 (arbitrary number) characters and see if there are unprintable characters, or if they are all ascii in a certain range. If the latter, assume that it is text?

    Whatever you do is going to be a guess.

提交回复
热议问题