⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample7.cs

📁 C#函数手册
💻 CS
字号:
namespace apiBook
{
	using System;
	using System.IO;
	public class TestFileInfoClass
	{
		public static void Main() 
		{				
			byte[] b=new byte[5];
			for(int i=0;i<5;i++)
				b[i]=(byte)i;
			Directory.CreateDirectory("C:\\language\\C#");
			string path="C:\\language\\C#\\testFileStream.txt";
			FileInfo  testFI = new FileInfo(path);
			//创建一个对象
			FileStream testFS=testFI.Create();
			//使用Create方法创建文件
			Console.WriteLine("往文件写入26个大写字母");
			testFS.SetLength(300);
			//使用SetLength方法设置流长度
			for(int i=0;i<26;i++)
			{
				testFS.WriteByte((byte)(';'));
				//使用WriteByte方法往文件里写入一个字节
				testFS.WriteByte((byte)(char)(65+i));					
			}
			testFS.Flush();
			//使用Flush方法清除该流的所有缓冲区,使所有缓冲的数据被写入基础设备
			testFS.Close();
			//使用Close方法关闭文件并释放与当前文件流关联的任何资源
			testFS=testFI.OpenRead();
			int counter=0;
			while(testFS.ReadByte()!=-1)
			{
				if(counter%5==0&&counter!=0)
					Console.WriteLine();
				char c=(char)(testFS.ReadByte());
				//使用ReadByte方法读取一个字节
				Console.Write(c);
				Console.Write(";");
				counter++;
			}
			testFS.Close();				
			Console.ReadLine();
		}			
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -