TXT的文件编码

来源:互联网 发布:js获取url后面的参数 编辑:程序博客网 时间:2024/05/02 06:12
无论是文本文件,还是unicode 和ascii 的编码,这些都是文件的解释方式。

举个例子,文件里有个单词"apple",那么现在要求用中文模式打开,那么就会显示“苹果”,但是对于的文件内容来说,它还是apple,并没有变,只是解释方式变了。

好,来回答lz的问题:
1、为什么用fopen打开文件要分二制度和文本文件模式?
这是两种解释方式

2、二种打开方式在实现上有什么区别吗?
与其说打开方式,不如说是文件内容的解释方式。
二进制就是以字节来读取写入,没有任何的附加动作。
文本方式对回车和换行符进行了处理,具体参看msdn的这段:


In text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function). 

3、文本文件有没有文件头?如果有,它的格式是什么?如果没有,它不就是一个纯01串流吗,我们怎么知道它是文本文件呢?
没有文件头。

4、文件文件的编码是怎么回事呢?unicode 和ascii 的编码 在文件里面是通过什么来区别出来的呢?
                  头3个字节(非ASCII)用来区别编码