Home > Article > Backend Development > How to open hidden files using C#?
To open a hidden file, make it visible first. You can do this by removing the hidden attributes set on it -
FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;
Now treat it as a normal text file and open it. Read the content -
using (StreamReader sr = new StreamReader("myFile.txt")) { string line; while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } }
After reading, set the properties to hidden again to hide the file -
file.Attributes |= FileAttributes.Hidden;
The above is the detailed content of How to open hidden files using C#?. For more information, please follow other related articles on the PHP Chinese website!