如何使用C#打开隐藏文件?
要打开隐藏文件,请首先使其可见。您可以通过删除设置在其上的隐藏属性来做到这一点-
FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;
现在将其视为普通文本文件并打开。阅读内容-
using (StreamReader sr = new StreamReader("myFile.txt")) {
string line;
while ((line = sr.ReadLine()) != null) {
Console.WriteLine(line);
}
}阅读后,再次将属性设置为hidden以隐藏文件-
file.Attributes |= FileAttributes.Hidden;
热门推荐
10 高一祝福语简短 励志
11 立秋节气简短祝福语
12 简短公司周年祝福语大全
13 中考感言简短祝福语大全
14 体育老师简短祝福语
15 干杯生日祝福语简短独特
16 特别简短的祝福语老师
17 朋友坐车走了祝福语简短
18 给英雄的祝福语简短