C#控制台基础 在查询硬盘的空间是出现system.IO.IOexception

来源:互联网 发布:linux python ide 编辑:程序博客网 时间:2024/05/20 19:46

镇场诗:慈心积善融学习,技术誓为大家学。善心速造多好事,前人栽树后乘凉。我今于此写经验,愿见文者得启发。
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






我的代码是:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;//这个using 不可缺少namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            var allDrives = DriveInfo.GetDrives();                        foreach(var aDrive in allDrives)            {                Console.WriteLine(aDrive.TotalFreeSpace);            }                         Console.ReadKey();        }           }}

改正代码,

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;//这个using 不可缺少namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            var allDrives = DriveInfo.GetDrives();                        foreach(var aDrive in allDrives)            {                if(aDrive.IsReady==true)//驱动器准备好了吗?                Console.WriteLine(aDrive.TotalFreeSpace);            }                         Console.ReadKey();        }           }}


刚才的错误出现在这里,我的CDROM是E盘,但是这个CDROM没有空间什么的,所以程序就尴尬了。



指导链接:http://bbs.csdn.net/topics/280049114

                 http://bbs.csdn.net/topics/350036201

                http://zhidao.baidu.com/link?url=36C9oYdK9mcfjElhJ6wJD_XQJtxmjQFvTgbfOPHi6dUkJpRdWa23UMrDg2AdNFuUhF8oyAbsPS9YytGOXOCaAq

         
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

感恩帮助过我的人。博客的精髓在技术部分,更在镇场一诗。
我是一个新手,代码还有许多不完善的地方,请您看代码的时候多多思考。
C#是一个优秀的语言,VS是一个优秀的编译软件,二者值得学习。如果您有一些不会的知识,咱们可以相互讨论。
如果您认为代码可以有改进的地方,有错误的地方,请留下评论,我会处理的。
注:如果我的博文无意中侵犯了您的权益,请告知。看到您的告知后,我将及时作出处理。
0 0
原创粉丝点击