C# 文件系统与字符串操作:从基础到实战
1. System.IO 命名空间基础
在 C# 编程中,System.IO 命名空间提供了处理文件和目录的强大功能。以下是一些关键的方法和类:
- Path 类方法 :
- GetFullPath() :用于获取文件的完整路径。路径是一个包含文件路径或目录信息的字符串对象。
- GetTempPath() :获取临时文件的存储位置。
- GetTempFileName() :获取一个可用的临时文件名。
以下是一个使用 Path 类的示例代码:
string pathWithExtension = @"c:\temp\path.txt";
string pathWithoutExtension = @"c:\temp\path";
if (Path.HasExtension(pathWithExtension))
{
Console.WriteLine("{0} has an extension.", pathWithExtension);
}
if (!Path.HasExtension(pathWithoutExtension))
{
Console.WriteLine("{0} has no extension.", pathWithoutExtension);
}
Console.WriteLine("{0} is the location for temporary files.",
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



