随笔 - 566  文章 - 2  评论 - 77  阅读 - 117万

随笔分类 -  IO

IO DirectoryInfo MoveTo 将某一个文件或目录移到以一个目录
摘要:1.使用DirectoryInfo.MoveTo时,将目标文件夹一定要是不存在,不然报错。代码如下:View Code 1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3stringwtqPath=@"c:\wtq";4stringwttqq=@"c:\wttq11";5DirectoryInfodi=newDirectoryInfo(path);6di.MoveTo(wttqq);2.将文件复制到另外一个目录中代码如下:View Code 1s 阅读全文
posted @ 2011-08-22 16:07 wtq 阅读(506) 评论(0) 推荐(0) 编辑
IO Directory DirectoryInfo
摘要:1.Directory和DirectoryInfo这两个类都是对文件进行操作,但Directory是静态类,所以它的执行效率会更高一点。2.对文件操作。我们可以这样认为,Directory和directoryInfo都是一样的,只是表现形式不一样。 3.获取目录的文件名称或者是文件夹名称。代码如下;View Code 1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3if(!Directory.Exists(path))4{56Directory.CreateDirectory(pat 阅读全文
posted @ 2011-08-22 15:08 wtq 阅读(279) 评论(0) 推荐(0) 编辑
IO 创建目录,并常见文件
摘要:1.创建目录。创建目录和文件1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3if(Directory.Exists(path))4{56Directory.Delete(path,true);7Directory.CreateDirectory(path);8using(StreamWritersw=File.CreateText(pathTxt))9{10sw.WriteLine("mynameiswtq");11sw.WriteLine("andwh 阅读全文
posted @ 2011-08-22 13:56 wtq 阅读(357) 评论(0) 推荐(0) 编辑
IO 创建错误日记
摘要:1,创建错误日记时,在添加数据完后应该关闭流。才能使文件流入到文件中区。 阅读全文
posted @ 2011-08-12 12:47 wtq 阅读(158) 评论(0) 推荐(0) 编辑
IO filestream 将流输入到文件中
摘要:代码如下;View Code stringpath=@"c:\temp\wtq_1.txt";byte[]byteDate=newByte[1000];char[]c;byte[]d;try{using(FileStreamfs=newFileStream(path,FileMode.Create,FileAccess.ReadWrite)){stringstr="我叫***,为什么我使用这种方式不会乱码";c=str.ToCharArray();Console.WriteLine(c.Length);Console.ReadLine();foreach 阅读全文
posted @ 2011-08-01 21:55 wtq 阅读(293) 评论(0) 推荐(0) 编辑
IO File.copy 实现文件的复制
摘要:如图:代码如下:View Code stringpath=@"c:\temp\MyTest.txt";stringpathCopy=@"c:\temp\MyTestCopy.txt";if(File.Exists(path)){File.Copy(path,pathCopy,true);File.Delete(path);} 阅读全文
posted @ 2011-07-31 01:09 wtq 阅读(477) 评论(0) 推荐(0) 编辑
IO 使用File创建文本 streamwrite 写入字符,streamread输出字符
摘要:1.利用File.CreateText()来创建文本文件。代码如下:代码如下:View Code staticvoidMain(string[]args){stringpath=@"c:\temp\MyTest.txt";if(!File.Exists(path)){try{using(StreamWritersw=File.CreateText(path)){sw.WriteLine("thisismyname");sw.WriteLine("whataboutyou");sw.Write("?Ifine");} 阅读全文
posted @ 2011-07-31 00:59 wtq 阅读(396) 评论(0) 推荐(0) 编辑
IO 使用readKey即时显示数据到控制台
摘要:View Code staticvoidMain(string[]args){ConsoleKeyInfoc=newConsoleKeyInfo();ConsoleKeyInfocki;do{cki=Console.ReadKey();if((cki.Modifiers&ConsoleModifiers.Control)!=0)Console.WriteLine("ctrl");if((cki.Modifiers&ConsoleModifiers.Alt)!=0)Console.WriteLine("alt");if((cki.Modif 阅读全文
posted @ 2011-07-30 23:53 wtq 阅读(267) 评论(0) 推荐(0) 编辑
IO 使用try catch 自动错误跳转
摘要:1,以下代码显示被除0的错误提示代码如下:View Code staticvoidMain(string[]args){intaa=Console.In.Read();Console.Out.Write(aa);Console.ReadLine();inta=10;intb=0;try{intc=a/b;}catch(DivideByZeroExceptionexe){Console.WriteLine(exe.Message+""+"不能被整除");Console.WriteLine(exe.HelpLink);Console.WriteLine(ex 阅读全文
posted @ 2011-07-30 22:52 wtq 阅读(366) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示