学习一下.NET文件类库

任何编程语言操作文件都要调用操作系统的应用程序接口来实现,.NET框架提供了功能强大的统一的应用程序接口,在System.IO命名空间下,定义了多种文件管理,文件和数据流读写的类型。
废话也就不多说了,我们来看下我参考微软的官方实例写的例子
using System;
using System.IO;
namespace 文件操作
{
    class Test
    {
        static void Main(string[] args)
        {
            string file = @"D:\test1.txt";
            if (!File.Exists(file))
            {
                File.Create(file);
            }
            else
            {
                try
                {
                    if ((File.GetAttributes(file) & FileAttributes.Hidden) == FileAttributes.Hidden)
                    //如果文件被隐藏
                    {
                        File.SetAttributes(file, FileAttributes.Archive);
                        Console.WriteLine("文件不再被隐藏");
                    }
                    else //如果文件没有被隐藏
                    {
	
相关新闻>>
- 发表评论
- 
				
- 最新评论 进入详细评论页>>



