Code
1 private void button1_Click(object sender, EventArgs e)
2 {
3 FileStream fs = new FileStream(@"c:\1.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);//创建文件
4
5 StreamWriter sw = new StreamWriter(fs);
6 // 以文本方式写一个文件
7 sw.WriteLine("Hello, World");
8 sw.WriteLine("你好吗?");
9 sw.WriteLine("我很好!");
10 sw.WriteLine("嘿嘿,示例好傻!");
11
12 sw.Flush(); //清理缓冲区
13
14
15 StreamReader sr = new StreamReader(fs);
16 sr.BaseStream.Seek(0, SeekOrigin.Begin);//定位到流的开始位置
17 String str=String.Empty;
18 while (!sr.EndOfStream) //未到文件流结尾
19 {
20 str += sr.ReadLine();
21 }
22
23
24 BinaryReader br = new BinaryReader(fs);
25 br.BaseStream.Seek(0, SeekOrigin.Begin);//定位到流的开始位置
26 Byte b = new Byte();
27 while (br.PeekChar() > -1)//定位到下一个字符
28 {
29 b += br.ReadByte();
30 }
31
32 //关闭文件流
33 sw.Close();
34 br.Close();
35 sr.Close();
36 fs.Close();
37
38
39 //获取文件信息
40 FileInfo fi = new FileInfo(@"c:\1.txt");
41 String str1 = fi.CreationTime + " " + fi.FullName;
42 }
posted @
2008-10-21 14:26
扯
阅读(
1184)
评论()
编辑
收藏
举报