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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - Tiu

2010走了,又是一年,留个脚印 Commerce Server 2007 随笔一 2009眨眼间过去了,留个纪念 asp.net ajax随笔二 asp.net中慎用static全局变量 asp.net ajax随笔一 收集的关于依赖注入及Unity application block入门的一些资料 2008最后一篇:总结与展望 防止页面在提交的过程中多次点击按钮 第一次使用SQLCLR C#网络编程随笔一 装AJAX.NET 1.0的环境,我遇到个问题,进来解答下 关于邮件群发 XML学习一 asp.net窗中的两个Form问题 URL重写入门 动态从数据库中选择Top 个数 关于在数据层返回SqlDataReader 编写类和子程序的几个原则
文件操作类简介
Tiu · 2008-12-16 · via 博客园 - Tiu

   以前写程序很少对文件进行操作,但如果操作的时候又不得不重新看msdn或者书籍,所以这里把操作文件的一些相关类整理一下,以后用到的时候就可以快速的进行浏览。

  1.首先是Directory类和File类,这两个类主要是提供一组静态方法用于操作电脑上的目录及文件,其中File类提供了Create()方法用于创建指定的文件并返回一个可用于写的FileStream对象,CreateText()方法返回StreamWrite对象,Open()指打开一个文件,OpenText()、OpenRead则返回一个FileStream或StreamWrite对象,OpenWrite()以只写方式打开文件,ReadAllText()读取整个文件,ReadAllLines()返回字符串数组,ReadAllBytes()返回字节数组,文件小的时候可以使用上述三种方法一次性的读取。同时对应上述三个方法的是WriteAllText(),WriteAllLines(),WriteAllBytes()

  2. DriveInfo、DirectoryInfo和FileInfo提供了类似功能的方法和属性

 3.Path类提供文件路径及目录路径相关的功能:例如:ChangeExtension()更改文件扩展名,GetFileName()得到路径的文件名部分,GetFileNameWithoutExtension得到路径的文件名部分(不包含扩展名),

4.FileStream只以字节或字节数组的方式工作。StreamWriter和StreamReader更加常用。

文本编码:

ASCII:用7比特编码字符串中的每个字符,使用ASCII编码的数据不能包括扩展的Unicode字符,.net里使用ASCII编码,位会被对齐,每个字符在结果字节数组里只占一个字节

完整Unicode(UTF-16)每个字符占两个字节

UTF-7:不常用

UTF-8:

BinaryWriter用于操作二进制类的文件。