标签:
在我的上一篇随笔“对 File.Delete 方法的一点看法”中,在 Windows 操作系统上对 File.Delete 方法进行了测试。这次,在 Linux 操作系统上使用 mono 的最新版本 1.2.5 版对 File.Delete 方法进行测试。文件名 |
直接调用 File.Delete 方法 ben@ibm7k:~/work$ mono test.exe |
零长度字符串 |
请输入要删除的文件名: 错误: System.ArgumentException: path at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
非法字符 |
请输入要删除的文件名: zero 错误: System.ArgumentException: path at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
空引用 |
请输入要删除的文件名: null 错误: System.ArgumentNullException: Argument cannot be null. Parameter name: path at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
无效的路径 |
请输入要删除的文件名: none/a.txt 错误: System.IO.DirectoryNotFoundException: Destination directory not found: none at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
文件名太长 |
请输入要删除的文件名: -this-string‘s-length-is-256- 错误: System.IO.PathTooLongException: Path is too long. Path: -this-string‘s-length-is-256- at System.IO.Directory.Exists (System.String path) [0x00000] at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
一个目录 |
请输入要删除的文件名: / 错误: System.UnauthorizedAccessException: / is a directory at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
没有权限的文件 |
请输入要删除的文件名: /etc/passwd 错误: System.UnauthorizedAccessException: Access to the path "/etc/passwd" is denied. at System.IO.File.Delete (System.String path) [0x00000] at Test.Main (System.String[] args) [0x00000] |
正在使用的文件 |
请输入要删除的文件名: test.exe File.Delete 成功 |
只读文件 |
请输入要删除的文件名: readonly.file File.Delete 成功 |
不存在的文件 |
请输入要删除的文件名: none.file File.Delete 成功 |
正常的文件 |
请输入要删除的文件名: readwrite1.file File.Delete 成功 |
版权声明:本文为博主http://www.zuiniusn.com原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u013948191/article/details/47163959