惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 阿齐

2013年1月18日 星期五 如何修改Panorama控件的Title 分享好用的截屏软件:SnagIt [转]如何在Windows Server 2012中安装.Net Framework 3.5? 屌丝笔记本玩Windows Phone 8开发(在Windows Server 2012中安装WP8 SDK) 在Ubuntu下的Firefox地址栏点击全选网页地址 Ubuntu下的Firefox差点让我崩溃 使用ICSharpCode.SharpZLib压缩/解压给定的数据 使用Base64编码数据量变大33.4% 旧文一篇:7年项目总结 在.Net中将MailMessage保存为本地eml文件 创业之三要素 让MSN Messager(Windows Live Messager)重回托盘 创业的Idea是怎样产生的? 我的恩师白玉玺先生-----转自北京崇文汇通武术网站,作者:柳宗林 记录一把,两个截取HTTP请求的工具 标记一下:两个免费的SVN服务 需要使用计算器才能做的投资,通常都不是好投资 解决“A problem has been encountered while loading the setup components. Canceling setup.”的问题 己丑年正月十九北京随想
如何判断文本文件的编码方式?
阿齐 · 2010-11-08 · via 博客园 - 阿齐

文本文件通常通过其前2个字节来标识自身的编码方式,但UTF-32编码则通过前4个字节来标识自己的编码方式。下面是一些编码格式的标识:

编码方式 前几个字节值
ANSI 无格式定义
Unicode FF FE
Unicode big endian FE FF
UTF-8 EF BB
UTF-16/UCS-2, little endian FE FF
UTF-16/UCS-2, big endian FF FE
UTF-32/UCS-4, little endian FF FE 00 00
UTF-32/UCS-4, big-endian 00 00 FE FF

这样一来,我们写代码的时候只需要读取文件的前2个字节~4个字节,即可知道其编码方式。但在.Net中,还有另一种更简单的办法可以知道文本文件的编码方式,及使用以下的代码:

public Encoding GetEncoding(string file)
{
    var r = new StreamReader(file, true); //这里的true表示由程序自动判断文件编码
    return r.CurrentEncoding; //返回编码
}