首页 > 其他 > 详细

文件内容的写入与读取

时间:2018-05-30 20:18:53      阅读:154      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1 //文件的读取方式一
 2 //直接读取文件
 3 
 4 string textContent=File.ReadAllText("路径","读取的文件内容类型");
 5 
 6 //文件读取 方式二
 7 
 8 string FileName=""//表示路径
 9 using(FlieStream fs=new FlieStream(FlieName,FileMode.open,FileAccess.Read))
10 {
11   using(StreamReader sr=new StreamReader(fs))
12     {
13       List<string> strList=new List<String>();
14         while(!sr.EndOfStream)
15         {
16              
17             strList.Add( sr.ReadLine());
18         }  
19     }          
20 }              
21 
22 
23 
24 //文件的写入
25 
26 //方式一 直接写入
27 
28 string txtContent=File.WriteAllText(“文件写入路径”,"写入的内容","内容呈现的格式");
29 
30 //方式二
31 
32 using(FileSteam fs=new FileStream("写入路径",FileMode.OpenOrCreate,FileAccess.ReadWrite))
33 {
34     string content="fsfasf";
35      byte[] strContent=Encoding.Default.GetBytes(content);
36      fs.Write(strContent,0,strContent.length);
37 }
38 
39 
40 //方式三 
41 
42 using(StreamWriter sw=new StreamWriter(“文件写入路径”,"","编码格式","写入的大小"))
43 {
44          sw.WriteLine(“写入的内容”);
45                  sw.Flush();
46 }
47 
48 
49           
View Code

写的不是咋好,希望大家看到有错误的地方指正。

文件内容的写入与读取

原文:https://www.cnblogs.com/wishbone/p/9112678.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!