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("这是演示文字!");
}
FileInfo info = new FileInfo("hello.txt");
FileAttributes attr = info.Attributes;
Console.WriteLine(attr);
}
}输出结果
Normal
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短