有关文件信息的 C# 程序
了解文件的信息是指获取为特定文件设置的所有属性。举例来说,文件可以是普通、隐藏、存档等。
首先,使用 FileInfo 类 −
FileInfo info = new FileInfo("hello.txt");现在,使用 FileAttributes 获取文件的信息 −
FileAttributes attr = info.Attributes;
以下是代码 −
示例
using System.IO;
using System;
public class Program {
public static void Main() {
using (StreamWriter sw = new StreamWriter("hello.txt")) {
sw.WriteLine("This is demo text!");
}
FileInfo info = new FileInfo("hello.txt");
FileAttributes attr = info.Attributes;
Console.WriteLine(attr);
}
}输出
Normal
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP